Thursday, April 12, 2012

Creating a view that display all records that belongs_to an association

I'm trying to create a view that display all records that belongs to an association and not sure on how to go about this.



I've created an erb file in view/members/showmembers.html.erb, added 'showmembers' method in members_controller.rb but when I go to http://localhost:3000/members/showmembers it says 'Couldn't find Member with id=showmembers' and its pointing to the show method in the controller *'app/controllers/members_controller.rb:29:in `show'*.



  def showmembers    
@organization = Organization.find(1)
@shmembers = @organization.members.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @members }
end
end


showmembers.html.erb



    <% @shmembers.each do |shmember| %>
<tr>
<td><%= shmember.id %></td>
<td><%= shmember.first_name %></td>
</tr>
<% end %>


Thanks.





No comments:

Post a Comment