jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Jan-14 05:48 UTC
undefined method `each'' for
Hi all. I am very new to ruby rails and I got this error.
undefined method `each'' for #<Video:0x370bdd8> in
selectaction.rhtml
that calls video controller
3: <table>
4: <tr>
5: <% x = 0 %>
6: <% for video in @videos %>
7: <td><%=
link_to(image_tag("videos/#{video.video_thumbnail}",
8: :size => ''132x99'',
9: :border => 5,
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1792:in
`method_missing''
#{RAILS_ROOT}/app/views/videos/selectaction.rhtml:6:in
`_run_rhtml_videos_selectaction''
In videos_controller
def selectaction
@videos = Video.find_by_subject("action")
end
Now I didn''t define find_by_subject, but doesn''t rails do that
for me
if I have a database table called video with with subject as a field?
And does ruby define video for me?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org wrote:> Hi all. I am very new to ruby rails and I got this error. > > undefined method `each'' for #<Video:0x370bdd8> in selectaction.rhtml > that calls video controller > 3: <table> > 4: <tr> > 5: <% x = 0 %> > 6: <% for video in @videos %>[snip]> In videos_controller > def selectaction > @videos = Video.find_by_subject("action") > endVideo.find_by_subject will only return 1 record. @videos then gets set to a single Video, and when you try to loop through a single video rather than a collection of them, you get ''undefined method ''each''. You want: @videos = Video.find_all_by_subject("action") Dan Manges --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Jan-14 06:10 UTC
Re: undefined method `each'' for
That worked. Thank you so much. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---