Colin Law wrote in post #1053187: > On 25 March 2012 07:40, Doe J. <li...@ruby-forum.com> wrote: >> package_line_item.rb >> has_many :menus , :through => :package_line_items, :uniq => true >> >> >> redirect_to @reservation ,:notice => "added menu" >> resources :package_line_items >> resources :menu_categories >> >> resources :recipes >> --------------------- >> package_line_item/show.html.erb >> >> <p id="notice"><%= notice %></p> >> <%= @reservation.package_line_items.menu.name%> > > You have not actually said but I presume the error is on the line > above. The error says that there is no method menu, consider what it > is that you are trying to call this method on: > @reservation.package_line_items > What is the type of that? The clue is that it is plural, so it is > probably a collection of items. You can't call menu on a collection > of items, you will have to select one at a time. > >> ----------------------- >> >> i tried on my show.html.erb file >> <%= @reservation.package_line_items.first.menu.name%> >> >> but it only returns the first menu that i added the when i open the >> second menu the information inside it is the the information in my first >> menu > > Right, that is because you are now calling it on the first such item. > If you want to show information for all the items you will have to > loop round them displaying the menu names. > > If you don't know how to do that then I suggest working through some > good tutorials such as railstutorial.org (which is free to use online) > which will give you a better understanding of Ruby and Rails. > > Colin
thanks mr colin sir i tried looping with <% @reservation.package_line_items.each do |menu|%> <p><%= menu.menu.name%></p> <%end%> but it is displaying all of the menus that the reservation not the specific menu that i clicked -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.