Rails3 通过单击按钮调用特定控制器的特定操作
在视图页面上有一个标签 <%= Submit_tag "Some text" %>它呈现相应控制器的“创建”操作(不是吗?)。是否可以通过单击按钮来呈现另一个控制器的操作?
On the view pages there is a tag <%= submit_tag "Some text" %> which renders the correspondent controller's 'create' action(isn't it?). Is it possible to render action of another controller's by the button click?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是可能的,但不能使用
submit_tag
方法。您想要更改相应的form_tag
方法,该方法接受'/posts'
或'/posts/your_action'
等参数。所以你可以这样做:问候
托比亚斯
That's possible, but not with the
submit_tag
method. You want to alter the correspondingform_tag
method, which accepts an argument like'/posts'
or'/posts/your_action'
. So you could do:Regards
Tobias
检查 link_to 和 button_to助手或模块本身
Check link_to and button_to helpers or the module itself