到 Rails 3 从 Rails 2 路由
我正在按照本教程发送激活电子邮件:
http://www.slideshare.net /JamesEdwardGrayII/sending-email-with-rails
我相当确定这是使用 Rails 2 完成的,并且路由对我来说有点问题。
routes.rb:
map.activate "activate/:token", :controller => "activations", :action => "create"
启用:
activate_url(:token => @user.perishable_token, :host => "localhost:3000")
以便发送 localhost:3000/:token
url 供用户激活。
为了使其适用于 Rails 3,我尝试了以下操作:
match 'activate/:token' => 'activations#create'
match 'activate/:token', :to => 'activations#create'
但 activate_url
不起作用。我希望得到一些意见。谢谢!
I am following this tutorial on sending activation email:
http://www.slideshare.net/JamesEdwardGrayII/sending-email-with-rails
I am fairly certain this was done with rails 2 and the routing has been a little problematic for me.
routes.rb:
map.activate "activate/:token", :controller => "activations", :action => "create"
enables:
activate_url(:token => @user.perishable_token, :host => "localhost:3000")
So that localhost:3000/:token
url is sent for the user to activate.
In order to make it work for rails 3, I have tried the following:
match 'activate/:token' => 'activations#create'
match 'activate/:token', :to => 'activations#create'
but activate_url
isn't working. I'd appreciate some input. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
routes.rb
中添加:as =>; 'activate'
到您的match
方法,如下所示:match 'activate/:token' => '激活#create', :as => 'activate'
如果您只使用 GET/POST,我会将路由更改为:对于 GET:
get 'activate/:index' => '激活#create', :as => 'activate'
或用于 POST
post 'activate/:index' => '激活#create', :as => '激活'
In your
routes.rb
add a:as => 'activate'
to yourmatch
method like this:match 'activate/:token' => 'activations#create', :as => 'activate'
and if you are only using GET/POST I'd change the route to this:For GET:
get 'activate/:index' => 'activations#create', :as => 'activate'
or for POST
post 'activate/:index' => 'activations#create', :as => 'activate'