如何向控制器添加新操作?

发布于 2024-10-08 22:49:16 字数 324 浏览 0 评论 0原文

我在路由中使用以下内容向我的电子邮件控制器添加新操作:

   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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心意如水 2024-10-15 22:49:16

尝试

link_to newfwd_email_path(1), :method => :put

:id => 11 一样好;)

Try

link_to newfwd_email_path(1), :method => :put

:id => 1 is as good as 1 ;)

感情洁癖 2024-10-15 22:49:16

您不需要将哈希传递给 newfwd_email_path 方法。尝试

newfwd_email_path(1)

编辑:您还需要使用 :method => :put 确保当服务器收到请求并且路由生效时使用 PUT 动词。

you do not need to pass a hash to the newfwd_email_path method. Try

newfwd_email_path(1)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文