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.