1

我正在研究生成看起来像https://mywebsite.com/user/check_email_confirmation/46cee41bc2044104aff8cf7746687ea8的网址

对于著名的“请单击此链接以确认您的电子邮件”。

所以我有一条路线,我打算在我的 routes.rb 中使用它:

  resources :user do
    collection do
      get  'check_email_confirmation/:generated_url', :to => 'user#check_email_confirmation'
    end
  end

现在,我的麻烦是生成上面的完整地址。我生成了 SHA (46cee41bc2044104aff8cf7746687ea8) 部分,但是如何在我的视图中编写“https://mywebsite.com/user/check_email_confirmation/”部分?

添加视图的代码:

<p>Please click <%= url_for(:action => 'check_email_confirmation', :controller => 'user', :only_path => false, :id => @confirmation_url) %> to confirm your e-mail address.</p>
4

2 回答 2

1

替换id:generated_url:

您还可以通过在路线中命名路线来简化url_foringas:

get  'check_email_confirmation/:generated_url', to: 'user#check_email_confirmation', as: :confirmation

更多信息请访问http://viget.com/extend/rails-named-routes-path-vs-url

于 2012-08-23T15:19:23.230 回答
0
get "check_email_confirmation/:id" => "users#check_email_confirmation", :as => "check_email_confirmation" 
于 2012-08-23T06:04:41.270 回答