导轨形式的隐藏场 [英] Hidden field in rails form

查看:67
本文介绍了导轨形式的隐藏场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中的视图中有此表单.我需要将task_id传递给某个控制器,但是日志似乎没有接收到参数.我不知道问题出在哪里.

I have this form in a view in my project. I need to pass the task_id to a certain controller, but the log does not seem to be receiving the parameters. I don't know what the problem is.

<%= 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 %>

推荐答案

<%之后,您在=上丢失了.每当您希望结果出现在HTML上时,都需要等号,因此,例如,它与字段标签方法或渲染器一起使用.例如,在使用if时,请勿使用equals,因为这不是您要打印的内容(可以,但是可以,但是很可能不是)

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)

<%= 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 %>

但是,正如@AntonGrigoriev所指出的,如果有的话,应该使用一个对象,就像这样

However, as @AntonGrigoriev pointed out, you should use a object if you have, like this

<%= form_for @task, :url => {:action=>"index", :controller=>"statistics"}, :html => {:class => "nifty_form", :method => "GET"} do |f| %>

,或者您只需使用 hidden_​​field_tag

<%= hidden_field_tag :task_id, task.id %>

这篇关于导轨形式的隐藏场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆