1

Error: "Param is missing or the value is empty :child"

I've nested objects (child controler & viewers are in Parent folder). On parent detail page I list all children in a table. Other methods like edit, update, new work. But I want to have a link with my method 'graduate' that enables to change child attribute graduate_date on the parent page. I attempt to do it by changing date of graduation for Time.now in Child controller#graduate action

class ParentsController
    def show
        @parent = Parent.find params[:id]
        @children = @parent.children
    end

-- Parent view --

<% @children.each do |child| %>
    <tr>
      <td><%= child.name %>
      <% if child.graduated? %>
        <td> graduated </td>
      <% else %>
        <td><%= link_to 'graduate now', graduate_parent_child_path(@parent, child) %></td>
      <% end %>
    </tr>
<% end %> 

-- models --

Parent: has_many
Child: belongs_to

-- child controller --

def graduate
  @parent = Parent.find params[:parent_id]                        ==> parent_id & id are correct
  @child = Child.find params[:id]
  @child.update_attribute(:graduation_date, Time.now.strftime(%m%d%Y)) ==> here does not updates!!!
end

-- routes.rb --

resources :parents do
    resources children, controller: parent/children do
        member { match :graduate, via [get, patch] }   ==> rails forces me to use get
    end
end

Rais forces me to use get in routes. I'm connected to controller, 2 first lines of 'graduate' work correctly but attributes are not updated but graduated_date has assigned nil instead.

Katarzyna
  • 1,712
  • 2
  • 11
  • 14

1 Answers1

0

In your ParentsController you set @child, but in your view you look for @children

mpugach
  • 591
  • 5
  • 15
  • Also 'children' is already plural form of 'child', not 'childrens' – mpugach Aug 14 '14 at 04:22
  • Good catch but it was my typo here since pasting code on stackoverflow is disabled. Basic code & all functionality work as I wrote but this particular method 'graduate' fails by the end. – Katarzyna Aug 14 '14 at 23:50