routing - Rails link_to question -


i building kid's chore app. in application.html.erb show side bar listing children's names:

  <div id="side">     <%= link_to "home", home_path %><br />     <% @children.each |child| %>         <%= link_to child.name, child_path(child.id) %><br />     <% end %>   </div> 

upon clicking child's name, want chores displayed.. code above "show" child when clicked.

i thinking like:

        <%= link_to child.name, chore_path %><br /> 

.. not work because:

  1. i lose child_id... need them record chores
  2. i routed http://localhost:3000/chores/1 (i want chores index)

how can keep child_id variable in example display chore index?

cheers, chris

associations below:

class child < activerecord::base   has_many :completion, :dependent => :destroy   has_many :chores, :through => :completion  class chore < activerecord::base   has_many :completions   has_many :kids, :through => :completions  class completion < activerecord::base   belongs_to :child   belongs_to :chore 

link_to child.name, chores_path(:child_id => child.id) 

then can grab child id in action params[:child_id]

the link /chores?child_id=1 example.


Comments