从参数中嵌套散列检索选项
问题描述:
我在视图中有以下代码,用于编辑规范状态(完成或未完成)。从参数中嵌套散列检索选项
%table
= form_for project_specification_path(@project,@specification), :method => :put do |f|
%tr
%td
= f.label :status, 'Status'
= f.select :status, ['Completed','Not completed']
%tr
%td
= f.submit 'Save'
点击“保存”后,在规格控制器的更新方法中,我需要更新@specification属性。
PARAMS如下:
=> {"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"Wp2OSBaOCP9aIx27B0ZTnvuFtN0m4O45efDwdA5KB5Q=",
"/projects/1/specifications/1"=>{"status"=>"Completed"},
"Status"=>"Save status",
"action"=>"update",
"controller"=>"specifications",
"project_id"=>"1",
"id"=>"1"}
我需要写类似@ specification.update_attributes(????),但我不知道如何检索参数:状态从嵌套的哈希值。
感谢
答
至#form_for
的第一个参数应该是一个模型实例或象征性的型号名称,而不是一个路径。应该使用:url => ...
选项提供自定义路径,所以类似...
= form_for :specification, :url => project_specification_path(@project,@specification), :method => :put do |f|
...