如何用form_for设置动作?
我在现有控制器上创建了一个新页面。
我在控制器上添加了 2 个操作方法:prompt_user 和 process_feedback。
因此,我通过以下方式进入该页面
redirect_to :controller => :users, :action => :prompt_user
, form_for 代码看起来像
<% form_for :user, @user do |f| %>
生成以下 html
<form action="users/prompt_user" method="post">
请注意,操作是提示用户,因为我想将其设置为 process_feedback。我以为我可以用按钮更改操作
<%= submit_tag "Process feedback" %>
,但这不起作用。
所以我的问题是如何将操作更改为 process_feedback?
另外,正如你可能知道的那样,我对 Rails 非常陌生,所以如果我正在做一些特别迟钝的事情,我很想知道它是什么。
I created a new page on an existing controller.
I added 2 action methods on the controller: prompt_user and process_feedback.
So I get to the page via
redirect_to :controller => :users, :action => :prompt_user
And the form_for code looks like
<% form_for :user, @user do |f| %>
Which generates the following html
<form action="users/prompt_user" method="post">
Notice the action is prompt_user, where as I want to set it to process_feedback. I thought I could change the action with a button
<%= submit_tag "Process feedback" %>
But that didn't work.
So my question is how can I change the action to process_feedback?
Also, as you can probably tell, I'm very new to rails, so if I'm doing something especially obtuse, I'd love to find out what it is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是凭记忆,但我认为你可以这样做:
This is from memory, but I think you can do something like this:
或者,可以使用
form_tag
实现相同的效果,语法如下:请参阅我对此问题的回答:此处 https:// /stackoverflow.com/a/37145293/1248725
Alternatively the same can be reached using
form_tag
with the syntax:See my answer on this question: here https://stackoverflow.com/a/37145293/1248725