2012-08-18 50 views
0

我在視圖中有以下代碼,用於編輯規範狀態(完成或未完成)。從參數中嵌套散列檢索選項

%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(????),但我不知道如何檢索參數:狀態從嵌套的哈希值。

感謝

回答

1

#form_for的第一個參數應該是一個模型實例或象徵性的型號名稱,而不是一個路徑。應該使用:url => ...選項提供自定義路徑,所以類似...

= form_for :specification, :url => project_specification_path(@project,@specification), :method => :put do |f| 
    ...