我正在研究生成类似于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>
答案 0 :(得分:1)
将id:
替换为generated_url:
。
您还可以通过路由中的url_for
命名路由来简化as:
get 'check_email_confirmation/:generated_url', to: 'user#check_email_confirmation', as: :confirmation
的详情
答案 1 :(得分:0)
get "check_email_confirmation/:id" => "users#check_email_confirmation", :as => "check_email_confirmation"