在我的Rails 4应用程序中,我有一个非常基本的形式:
<%= form_for @job, url: job_path(@job.id), html: {class: "form-horizontal group-border-dashed"} do |f| %>
<%= f.select :client_id, options_for_select(@clients_array), { :include_blank=>false }, {class: "form-control"} %>
<%= f.select :data_destruction, options_for_select([['Single Pass Wipe'],['Three Pass Wipe']]), { :include_blank=>false }, {class: "form-control"} %>
<%= f.text_field :no_items, :class => "form-control" %>
<%= f.text_field :collection_date, class: "form-control datepicker" %>
<%= f.select :priority, options_for_select([['Low'],['Medium'],['High'],['Urgent']]), { :include_blank=>false }, {class: "form-control"} %>
<%= f.text_area :warehouse_notes, class: "form-control" %>
<%= f.text_area :admin_notes, class: "form-control" %>
<%= f.select :reporting_required, options_for_select([['Yes'],['No']]), { :include_blank=>false }, {class: "form-control"} %>
<%= f.text_field :contact_user, class: "form-control" %>
<%= f.text_field :third_party_destruction, class: "form-control" %>
<button type="submit" class="btn btn-primary">Save</button>
<% end %>
提交表单后,它会正确路由到Jobs#Update。但是,params[:job]
哈希是空的:
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"KyJebi85lhfUV/klwa2icmniravyif/REF8HD+tI5GM=", "job"=>{}, "action"=>"update", "controller"=>"jobs", "id"=>"17"}
然而,当我检查request.request_parameters
时,我可以看到params被正确发送:
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"KyJebi85lhfUV/klwa2icmniravyif/REF8HD+tI5GM=", "job"=>{"client_id"=>"25", "data_destruction"=>"Single Pass Wipe", "no_items"=>"1500", "collection_date"=>"", "priority"=>"Low", "warehouse_notes"=>"Sample Warehouse Notes333", "admin_notes"=>"Sample Notes", "reporting_required"=>"Yes", "contact_user"=>"user5", "third_party_destruction"=>"NA"}, "action"=>"update", "controller"=>"jobs", "id"=>"17"}
有人可以解释为什么params[:job]
不包含任何属性吗?
提前致谢。