i just created an application to list the primary details of userbut it is showing an error lik this "uninitialized constant UsersController::User" this is my controlller class UsersController < ApplicationController puts"hiiiiiiiii" def index puts"hiiiiiiiii" @users = User.find(:all) puts @users respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end end this is my view file <h1>Users List</h1> <table> <tr> <th>Name</th> <th>Age</th> <th>Designation</th> <th>Hobby</th> </tr> <% @user.each do |user| %> <tr> <td><%=h user.name %></td> <td><%=h user.age %></td> <td><%=h user.designation %></td> <td><%=h user.hobby %></td> <!--<td><%= link_to ''Show'', job %></td> <td><%= link_to ''Edit'', edit_job_path(job) %></td> <td><%= link_to ''Destroy'', job, :confirm => ''Are you sure?'', :method => :delete %></td>--> </tr> <% end %> </table> and my model is this class User < ActiveRecord::Base end can anyone tell how to solve this -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Feb 25, 2010 at 6:14 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> i just created an application to list the primary details of > userbut it is showing an error lik this > "uninitialized constant UsersController::User"Is the user model defined in app/models/user.rb ? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Xavier Noria wrote:> On Thu, Feb 25, 2010 at 6:14 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> i �just �created an application �to list the �primary �details of >> userbut it is �showing an error lik this >> "uninitialized constant UsersController::User" > > Is the user model defined in app/models/user.rb ?yes it is defined in app/models/User.rb ? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Feb 25, 2010 at 6:28 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Xavier Noria wrote: >> On Thu, Feb 25, 2010 at 6:14 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> >>> i �just �created an application �to list the �primary �details of >>> userbut it is �showing an error lik this >>> "uninitialized constant UsersController::User" >> >> Is the user model defined in app/models/user.rb ? > > yes it is defined in app/models/User.rb ?lowercase "u". -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Xavier Noria wrote:> On Thu, Feb 25, 2010 at 6:28 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> yes it is defined in app/models/User.rb ? > lowercase "u".when i changed to lower case it shows an other error undefined local variable or method `user'' for #<UsersController:0xb6be1a70> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Xavier Noria
2010-Feb-25 06:02 UTC
Re: Re: Re: uninitialized constant UsersController::User
On Thu, Feb 25, 2010 at 6:46 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Xavier Noria wrote: >> On Thu, Feb 25, 2010 at 6:28 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> >>> yes it is defined in app/models/User.rb ? >> lowercase "u". > when i changed to lower case it shows an other errorI mean, the filename has to be "user.rb", with a lowercase "u". -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tony Augustine wrote:> Xavier Noria wrote: >> On Thu, Feb 25, 2010 at 6:14 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> >>> i �just �created an application �to list the �primary �details of >>> userbut it is �showing an error lik this >>> "uninitialized constant UsersController::User" >> >> Is the user model defined in app/models/user.rb ? > > yes it is defined in app/models/User.rb ?i changed but now its showing this error Showing app/views/users/index.html.erb where line #13 raised: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each Extracted source (around line #13): 10: <th>Hobby</th> 11: </tr> 12: 13: <% @user.each do |user| %> 14: <tr> 15: <td><%=h user.name %></td> 16: <td><%=h user.age %></td> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Feb 25, 2010 at 7:18 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> i changed but now its showing this error > > > > > Showing app/views/users/index.html.erb where line #13 raised: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > > Extracted source (around line #13): > > 10: <th>Hobby</th> > 11: </tr> > 12: > 13: <% @user.each do |user| %>Note you put the collection in @users, plural. The variable @user is unset and thus nil, hence the error. You need to replace @user with @users in the view. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Xavier Noria wrote:> On Thu, Feb 25, 2010 at 7:18 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> >> Extracted source (around line #13): >> >> 10: � � <th>Hobby</th> >> 11: � </tr> >> 12: >> 13: <% @user.each do |user| %> > > Note you put the collection in @users, plural. The variable @user is > unset and thus nil, hence the error. You need to replace @user with > @users in the view.thanks a lot for replying to ma silly doubts an wy cya -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<% for user in @users %> <tr> <td><%=h user.name %></td> <td><%=h user.age %></td> </tr> <%end%> check it out On Thu, Feb 25, 2010 at 11:52 AM, Xavier Noria <fxn-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Thu, Feb 25, 2010 at 7:18 AM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > > > i changed but now its showing this error > > > > > > > > > > Showing app/views/users/index.html.erb where line #13 raised: > > > > You have a nil object when you didn''t expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.each > > > > Extracted source (around line #13): > > > > 10: <th>Hobby</th> > > 11: </tr> > > 12: > > 13: <% @user.each do |user| %> > > Note you put the collection in @users, plural. The variable @user is > unset and thus nil, hence the error. You need to replace @user with > @users in the view. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Thanks: Rajeev sharma -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.