Ruby-on-rails 轨道形式的隐藏字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16280341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hidden field in rails form
提问by HeshamW
I have this form in a view in my project. I need to pass the task_idto a certain controller, but the log does not seem to be receiving the parameters. I don't know what the problem is.
我在我的项目的一个视图中有这个表单。我需要将 传递task_id给某个控制器,但日志似乎没有接收参数。我不知道是什么问题。
<%= form_for :taskid, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>
<%f.hidden_field :task_id, :value => task.id%>
<td><%= f.submit "???? ???? ?????? ?????????? ??????"%></td>
<% end %>
回答by fotanus
You are missing on =after <%. The equal sign is needed whenever you want to the result appears on the HTML, so it is used with the field tags methods or render, for instance. You should not use the equal when using a if, for example, because this is not what you want to print (well, it can be, but most likely it isn't)
你失踪了=之后<%。每当您希望结果出现在 HTML 上时都需要等号,因此它可以与字段标记方法或渲染一起使用,例如。if例如,在使用 a 时不应使用 equal ,因为这不是您想要打印的内容(好吧,它可以,但很可能不是)
<%= form_for :taskid, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>
<%= f.hidden_field :task_id, :value => task.id%>
<td><%= f.submit "???? ???? ?????? ?????????? ??????"%></td>
<% end %>
However, as @AntonGrigoriev pointed out, you should use a object if you have, like this
但是,正如@AntonGrigoriev 所指出的,如果有的话,您应该使用一个对象,就像这样
<%= form_for @task, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>
or you can simply use the hidden_field_tag
或者你可以简单地使用hidden_field_tag
<%= hidden_field_tag :task_id, task.id %>
回答by ram sharma
Hi please test with following code to send hidden value in rails, I have tried and worked for one of my application :
嗨,请使用以下代码进行测试以在 rails 中发送隐藏值,我已经尝试并为我的一个应用程序工作:
hidden_field_tag(name, value = nil, options = {})public
eg:
hidden_field_tag(name, value = nil, options = {})公开例如:
<%= hidden_field_tag(:field_name,value=@offer_status)%>

