如何向控制器添加新操作?
我在路由中使用以下内容向我的电子邮件控制器添加新操作:
map.resources :emails, :member => { :newfwd => :put}
预期结果是 newfwd_email_path(:id => 1) 将生成以下 url: emails/1/newfwd
确实如此。但我收到一个错误,它将“1”视为操作,将“newfwd”视为 id。我希望将“1”解释为电子邮件的 ID,newfwd 操作将根据该 ID 进行操作。
我不确定我做错了什么。 (注:我使用的是Rails 2.3.8)
I used the following in routes to add a new action to my Email controller:
map.resources :emails, :member => { :newfwd => :put}
The expected result was that newfwd_email_path(:id => 1) would generate the following urL: emails/1/newfwd
It does. But I get an error, it treats '1' as an action and 'newfwd' as an id. I want '1' to be interpreted as the id for emails, upon which the newfwd action acts.
I'm not sure what I'm doing wrong. (Note: I am using Rails 2.3.8)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
:id => 1
与1
一样好;)Try
:id => 1
is as good as1
;)您不需要将哈希传递给 newfwd_email_path 方法。尝试
编辑:您还需要使用 :method => :put 确保当服务器收到请求并且路由生效时使用 PUT 动词。
you do not need to pass a hash to the newfwd_email_path method. Try
EDIT: you also need to use :method => :put to ensure that the PUT verb is used when request is received on the server and routing comes into effect.