hidden_​​field_tag没有在params中发布

时间:2015-07-03 19:59:02

标签: ruby-on-rails forms post parameters hidden-field

我有以下表格,其中包含隐藏的字段标记,但是当我查看已发布的参数时,该隐藏的字段参数不会发布。有没有人对这种形式的隐藏字段有什么问题有任何想法?

<%=form_for '/schedule_path' do  |f|%>
<% @total_hrs = 0 %>
<table>
  <table class = "responstable" id ="form-table">
    <tr>
      <th>Employee</th>
      <th>Job 1</th>
      <th>Hrs</th>
      <th>Job 2</th>
      <th>Hrs</th>
      <th>Job 3</th>
      <th>Hrs</th>
      <th>Total</th>
      <th>Planned</th>
    </tr>
    <% @collectionsearch = "select jobs.id as id, jobs.name as name from jobs join (Select* from schedule_plans  where schedule_plans." + @col + " >0 and schedule_plans.user_id =" + @userid.to_s + ") sp on sp.job_id = jobs.id order by name asc" 
    @collection = Hash[Job.connection.select_all(@collectionsearch).rows] %>
    <% @schedule.each do |schedule| %>
       <%
               @hrs1 = schedule.hrs1.to_f
               @hrs2 = schedule.hrs2.to_f
               @hrs3 = schedule.hrs3.to_f
               @search = "Select "+@col+" FROM employees where id= "+schedule.employee.id.to_s+" and user_id = "+current_user.id.to_s 
               @planned_hrs = Employee.connection.select_value(@search).to_f 


               @total_hrs = @total_hrs + @planned_hrs              
       %>
       <% if schedule.employee.status && @planned_hrs > 0%>

         <tr>
          <%= f.fields_for :schedules, index: schedule.id do |sf| %>

              <% @check = false %>
              <td class = "large-col" > <%= schedule.employee.name %> </td>
              <td> <%= if (schedule.job1.nil?)  
                    sf.collection_select :job1, @collection, :first, :last, include_blank: 'Select a job'
                else
                    sf.collection_select :job1, @collection, :first, :last, selected: schedule.job1
                end
                %> 
              </td>
              <td class= "small-col"> <%= if (schedule.hrs1.nil?)  
                    sf.number_field :hrs1, placeholder: "Hrs" , :step => 'any' 
                else
                    sf.number_field :hrs1, value: @hrs1 , :step => 'any' 
                end
                 %> 
              </td>
              <td > <%= if (schedule.job2.nil?)  
                    sf.collection_select :job2, @collection, :first, :last, include_blank: 'Select a job'
                else
                    sf.collection_select :job2, @collection, :first, :last, selected: schedule.job2
                end
                %> 
              </td>
              <td class= "small-col"> <%= if (schedule.hrs2.nil?)  
                    sf.number_field :hrs2, placeholder: "Hrs" , :step => 'any' 
                else
                    sf.number_field :hrs2, value: @hrs2  , :step => 'any' 
                end
                 %> 
              </td>
              <td > <%= if (schedule.job3.nil?)  
                    sf.collection_select :job3, @collection, :first, :last, include_blank: 'Select a job'
                else
                    sf.collection_select :job3, @collection, :first, :last, selected: schedule.job3
                end
                %> 
              </td>
              <td class= "small-col"> <%= if (schedule.hrs3.nil?)  
                    sf.number_field :hrs3, placeholder: "Hrs" , :step => 'any' 
                else
                    sf.number_field :hrs3, value: @hrs3 , :step => 'any' 
                end
                 %> 
              </td>
              <td class = "small-col" > <%= @hrs1+ @hrs2 + @hrs3 %> </td>
              <td class = "small-col" >  <%= @planned_hrs %> </td>

          <% end %>
        </tr>
       <% end %>



       <%end %>
 <% if @total_hrs == 0 %>
         <p class = "alert-danger"> Alert -You have not defined employee availability. Please go to Labor Management > Employees and define working hours for each employee. </p>
       <%end%>     

  </table>
  <%= f.hidden_field_tag :date, @date %>
  <%= f.submit "Add", class: "btn btn-primary" %> 
  <% end %>

参数:

    Processing by SchedulesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"OjqNrvs3JWbtbs01XA3qnYk4Mv1+OstxcWCu3xDKo7NrN9GeHTsfK+VC1CGAC2S909NiPLofOXgEO5ES/kvB1Q==", "/schedule_path"=>{"schedules"=>{"391"=>{"job1"=>"1", "hrs1"=>"7.0", "job2"=>"4", "hrs2"=>"3.0", "job3"=>"", "hrs3"=>""}, "392"=>{"job1"=>"1", "hrs1"=>"3.0", "job2"=>"1", "hrs2"=>"4", "job3"=>"", "hrs3"=>""}}}, "commit"=>"Add"}

我在另一种形式中使用相同的hidden_​​tag字段,它工作正常:

<%= form_for(@user, url: password_reset_path(params[:id])) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

  <%= hidden_field_tag :username, @user.username %>

  <%= f.label :password %>
  <%= f.password_field :password, class: 'form-control' %>

  <%= f.label :password_confirmation, "Confirmation" %>
  <%= f.password_field :password_confirmation, class: 'form-control' %>

  <%= f.submit "Update password", class: "btn btn-primary" %>
<% end %>

1 个答案:

答案 0 :(得分:1)

我以为我之前尝试过这个,但在提交问题之后我给了它最后一次机会:

我改变了

<%= f.hidden_field_tag :date, @date %>
<%= hidden_field_tag :date, @date %>

开始工作了。