ruby on rails - In a show action, how to list objects that are in a associated model? -
what want here list entries of each activities in project.
app/controllers/projects_controller.rb :
class projectscontroller < applicationcontroller def index @projects = project.all end def show @project = project.find(params[:id]) @activities = @project.activities end end
app/views/projects/show.html.erb :
<div> <p><%= @project.description %></p> <% @activities.each |activity| %> <div> <p><%= activity.name %></p> <% activity.entries.each |entry| %> <= error @ line <p><%= entry.name %></p> <% end %> </div> <% end %> </div>
my models :
- project : has many activities
- activity : has many entries, belongs project
- entry : belong activity
the error obtain when run : "uninitialized constant activity::saisy" on show file
i don't know if can put each loop inside other each loop ? maybe that's problem, can't find other way it...
thanks lot help.
try renaming activity
a
, maybe activity
reserved work
<div> <p><%= @project.description %></p> <% @activities.each |a| %> <div> <p><%= a.name %></p> <% a.entries.each |entry| %> <p><%= entry.name %></p> <% end %> </div> <% end %> </div>
Comments
Post a Comment