Hey everybody, I''m trying to make an example of a small networking site, and when I log in a user, it should redirect and show his profile, but I get the following error: NoMethodError in User#index Showing app/views/user/index.html.erb where line #5 raised: undefined method `screen_name'' for nil:NilClass Extracted source (around line #5): 2: Your basic information 3: </h2> 4: <ul> 5: <li>Screen name: <%= @user.screen_name %></li> 6: <li>Email: <%= @user.email %></li> 7: <li>Password: ********** </li> 8: </ul> Thanks a lot to everybody! -- 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 Sat, Aug 14, 2010 at 6:19 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m trying to make an example of a small networking site, and when I log > in a user, it should redirect and show his profile, but I get the > following error:> undefined method `screen_name'' for nil:NilClass > Extracted source (around line #5):> 5: <li>Screen name: <%= @user.screen_name %></li>It means you haven''t set @user to anything (or inadvertently set it to nil); look at your controller code. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
Hassan Schroeder wrote:> On Sat, Aug 14, 2010 at 6:19 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> I''m trying to make an example of a small networking site, and when I log >> in a user, it should redirect and show his profile, but I get the >> following error: > >> undefined method `screen_name'' for nil:NilClass >> Extracted source (around line #5): > >> 5: � <li>Screen name: <%= @user.screen_name %></li> > > It means you haven''t set @user to anything (or inadvertently set it to > nil); look at your controller code. > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanWell, this is my code: def login @title = "Log in to RailsSpace" if request.get? @user = User.new(:remember_me => cookies[:remember_me] || "0") elsif params_posted?(:user) @user = User.new(params[:user]) user = User.find_by_screen_name_and_password(@user.screen_name,@user.password) if user user.login!(session) if @user.remember_me? ? user.remember!(cookies) : user.forget!(cookies) flash[:notice] = "User #{user.screen_name} logged in!" redirect_to_forwarding_url else @user.clear_password! flash[:notice] = "Invalid screen name/password combination" end end end end private def redirect_to_forwarding_url if (request_url = session[:protected_page]) session[:protected_page] = nil redirect_to request_url else redirect_to :action => "index" end end -- 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 Sat, Aug 14, 2010 at 6:46 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> It means you haven''t set @user to anything (or inadvertently set it to >> nil); look at your controller code.> Well, this is my code:>> NoMethodError in User#indexWhere is the method for `index` ? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
Hassan Schroeder wrote:> On Sat, Aug 14, 2010 at 6:46 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >>> It means you haven''t set @user to anything (or inadvertently set it to >>> nil); look at your controller code. > >> Well, this is my code: > >>> NoMethodError in User#index > > Where is the method for `index` ? > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanOnly this: def index @title = "RailsSpace User Hub" end -- 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 Sat, Aug 14, 2010 at 6:56 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>>>> It means you haven''t set @user to anything (or inadvertently set it to >>>> nil); look at your controller code.> def index > @title = "RailsSpace User Hub" > endUh, OK. See any "@user" there ? :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
Hassan Schroeder wrote:> On Sat, Aug 14, 2010 at 6:56 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >>>>> It means you haven''t set @user to anything (or inadvertently set it to >>>>> nil); look at your controller code. > >> def index >> � �@title = "RailsSpace User Hub" >> end > > Uh, OK. See any "@user" there ? :-) > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanHehe, ok, I just wrote @user = User.find_by_screen_name_and_email(@user.screen_name,@user.email) but now, when I click the login button in order to log in my user, I don''t get redirected -- 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 Sat, Aug 14, 2010 at 7:23 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hehe, ok, I just wrote > @user > User.find_by_screen_name_and_email(@user.screen_name,@user.email)That seems a little circular -- you''re going to assign @user by using attributes of @user ?? :-)> but now, when I click the login button in order to log in my user, I > don''t get redirectedI''d suggest checking your log file. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
Hassan Schroeder wrote:> On Sat, Aug 14, 2010 at 7:23 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> Hehe, ok, I just wrote >> @user >> User.find_by_screen_name_and_email(@user.screen_name,@user.email) > > That seems a little circular -- you''re going to assign @user by using > attributes of @user ?? :-) > >> but now, when I click the login button in order to log in my user, I >> don''t get redirected > > I''d suggest checking your log file. > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanAlright man, the first was easy! @user = User.find(session[:user_id]), thanks a lot :) The second one, I''m afraid that will need a little more research because I can''t find anything in the development.log Thanks! -- 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 14 August 2010 19:06, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hassan Schroeder wrote: >> On Sat, Aug 14, 2010 at 7:23 AM, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> >>> Hehe, ok, I just wrote >>> @user >>> User.find_by_screen_name_and_email(@user.screen_name,@user.email) >> >> That seems a little circular -- you''re going to assign @user by using >> attributes of @user ?? :-) >> >>> but now, when I click the login button in order to log in my user, I >>> don''t get redirected >> >> I''d suggest checking your log file. >> >> -- >> Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >> twitter: @hassan > > Alright man, the first was easy! > @user = User.find(session[:user_id]), thanks a lot :) > The second one, I''m afraid that will need a little more research because > I can''t find anything in the development.logIf you can''t work out what is happening to the flow in your code it can often be useful to use ruby-debug to break in to your code, where you can inspect data and step through the code. See the Rails Guide on debugging. Colin -- 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.
Colin Law wrote:> On 14 August 2010 19:06, Manu Lorenzo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >> @user = User.find(session[:user_id]), thanks a lot :) >> The second one, I''m afraid that will need a little more research because >> I can''t find anything in the development.log > > If you can''t work out what is happening to the flow in your code it > can often be useful to use ruby-debug to break in to your code, where > you can inspect data and step through the code. See the Rails Guide > on debugging. > > ColinWell, I tried, but I get lots of errors, even with ruby-debug19 -as I am using Ruby 1.9.1-p249- but I keep getting errors and that prevent me being able to use it: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\>gem install ruby-debug19 Building native extensions. This could take a while... ERROR: Error installing ruby-debug19: ERROR: Failed to build gem native extension. C:/Ruby191/bin/ruby.exe extconf.rb checking for vm_core.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=C:/Ruby191/bin/ruby --with-ruby-dir --without-ruby-dir --with-ruby-include --without-ruby-include=${ruby-dir}/include --with-ruby-lib --without-ruby-lib=${ruby-dir}/lib C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:364:in `try_do'': The complier failed to genera te an executable file. (RuntimeError) You have to install development tools first. from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:433:in `try_cpp'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:811:in `block in have_header'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:670:in `block in checking_for'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:276:in `block (2 levels) in postp one'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:250:in `open'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:276:in `block in postpone'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:250:in `open'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:272:in `postpone'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:669:in `checking_for'' from C:/Ruby191/lib/ruby/1.9.1/mkmf.rb:810:in `have_header'' from extconf.rb:15:in `block in <main>'' from C:/Ruby191/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.4/lib/ruby _core_source.rb:18:in `call'' from C:/Ruby191/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.4/lib/ruby _core_source.rb:18:in `create_makefile_with_core'' from extconf.rb:20:in `<main>'' Gem files will remain installed in C:/Ruby191/lib/ruby/gems/1.9.1/gems/linecache 19-0.5.11 for inspection. Results logged to C:/Ruby191/lib/ruby/gems/1.9.1/gems/linecache19-0.5.11/ext/tra ce_nums/gem_make.out C:\> -- 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.