Hidden field in rails form

前端 未结 2 979
野性不改
野性不改 2021-02-01 04:08

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 kno

2条回答
  •  孤独总比滥情好
    2021-02-01 04:43

    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%>
      <%= f.submit "اختر مهمة لاظهار احصائياتها منفرده"%>
    <% end %>
    

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

    or you can simply use the hidden_field_tag

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

提交回复
热议问题