vladCovaliov
vladCovaliov

Reputation: 4403

Retrieve option from nested hash in params

I have the following code in views, for editing a specification status ( Completed or Not completed) .

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

After click-ing 'Save', in the update method from specifications controller, i need to update the @specification attributes.

params looks like this :

=> {"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"Wp2OSBaOCP9aIx27B0ZTnvuFtN0m4O45efDwdA5KB5Q=",
 "/projects/1/specifications/1"=>{"status"=>"Completed"},
 "Status"=>"Save status",
 "action"=>"update",
 "controller"=>"specifications",
 "project_id"=>"1",
 "id"=>"1"}

I need to write something like @specification.update_attributes(????) but i don't know how to retrieve the parameter :status from the nested hash.

Thanks

Upvotes: 0

Views: 189

Answers (1)

Steve Jorgensen
Steve Jorgensen

Reputation: 12341

The first parameter to #form_for should be a model instance or a symbolic model name, and not a path. A custom path should be supplied using the :url => ... option, so something like...

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

Upvotes: 1

Related Questions