Hello, I realize that the reason I am getting this error is because my code returns many records when there is more than one to be found. However, if it only finds one, the each.do flakes out and gives me a NoMethodError. What is the best way to handle it? # -- Find all events for a given school @events = Event.find_by_school_id(params[:school_id], :order => ''date'') # -- each.do code to loop through each one: <table class="eventList"> <tr><th>Time</th><th>Title</th><th>Description</th></tr> <% @events.each do |e|%> <tr> <td><%= e.date.strftime(''%I:%M %p'') %></td> <td><%= link_to e.title, :action => ''show'', :id => e.id %></td> <td><%= link_to e.school.name, :action => ''list'', :school_id => e.school %> </tr> <% end %> </table> Thank you for you help --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/7/07, Anthony <bonesreview-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, I realize that the reason I am getting this error is because my > code returns many records when there is more than one to be found. > However, if it only finds one, the each.do flakes out and gives me a > NoMethodError. What is the best way to handle it? > > # -- Find all events for a given school > @events = Event.find_by_school_id(params[:school_id], :order => > ''date'')I think you want @events = Event.find_all_by_school_id(...) find_by_school_id only returns the first found. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That''s it. Thank you. On Dec 7, 11:55 am, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/7/07, Anthony <bonesrev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello, I realize that the reason I am getting this error is because my > > code returns many records when there is more than one to be found. > > However, if it only finds one, the each.do flakes out and gives me a > > NoMethodError. What is the best way to handle it? > > > # -- Find all events for a given school > > @events = Event.find_by_school_id(params[:school_id], :order => > > ''date'') > > I think you want > @events = Event.find_all_by_school_id(...) > > find_by_school_id only returns the first found. > > -- > Rick DeNatale > > My blog on Rubyhttp://talklikeaduck.denhaven2.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---