I have a view template "list_users.rhtml". On one line, I have <% @users = User.find(:all) %> in my models directory I have a file user.rb which starts with the line class User < ActiveRecord::Base Problem: When I invoke list_user.rhtml, I''m getting the error "Uninitialized constant User" which points at the User.find line listed above. It''s my understanding that find is built into the ActiveRecord class, so I think this is implying that it doesn''t see my class. Why? What else might I need to do to make sure my model file gets loaded? thanks in advance ---Michael -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Hi Michael, Michael Satterwhite wrote:> I have a view template "list_users.rhtml". On one line, > I have > <% @users = User.find(:all) %>You should be doing this in your controller, not your view.> Problem: When I invoke list_user.rhtml,What to you mean "invoke"? Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Michael, > Problem: When I invoke list_user.rhtml, > > What to you mean "invoke"?Bad choice of words. Actually rails invokes it when the list_users action in the controller is called.> > Bill-- 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-/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 -~----------~----~----~----~------~----~------~--~---
Michael Satterwhite> Bill Walton wrote: >> Hi Michael, >> Problem: When I invoke list_user.rhtml, >> >> What to you mean "invoke"? > > Bad choice of words. Actually rails invokes it when the list_users > action in the controller is called.Have you tried moving the find into the controller? If so and you''re still having problems, you''ll need to supply more info. Sorry I can''t be more help yet. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sat, 2006-10-07 at 19:18 +0200, Michael Satterwhite wrote:> I have a view template "list_users.rhtml". On one line, I have > > <% @users = User.find(:all) %> > > in my models directory I have a file user.rb which starts with the line > > class User < ActiveRecord::Base > > Problem: When I invoke list_user.rhtml, I''m getting the error > "Uninitialized constant User" which points at the User.find line listed > above. It''s my understanding that find is built into the ActiveRecord > class, so I think this is implying that it doesn''t see my class. Why? > What else might I need to do to make sure my model file gets loaded?you model class is fine the way it is. in app/controllers/UserController.rb you should have a method that has the same name as the template you want rails to automagically call. This method needs to pass the template a class variable (preceded by a ''@'') the template can have access to: def list_users # same name as template @all_users = User.find(:all) # note @ before var name end # no need to invoke anything then in app/views/users/list_users.rhtml you can access the collection of users via the class variable @all_users example: <ul> <% foreach user in @all_users %> <li><%= user.name </li> <% end %> </ul> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---