Hi I have problem trying to pass the signin failure test. This is the test code of the sessions_controller.rb def create user = User.authenticate(params[:session][:email], params[:session][:password]) if user.nil? flash.now[:error] = "Invalid email/password combination." @title = "Sign in" render ''new'' else # Sign the user in and redirect to the user''s show page. end end If I check in my browser and clic on submit with all fields empty, I get the following error: NoMethodError in SessionsController #create undefined method `nil'' for nil:NilClass I check the book many times and I have code exactly as the book, but I still have the error. Any help??? You can check the code in this link listing 9.8 http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:signin_failure What I doing wrong? Thanks for any 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-/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.
Aline de Oliveira Freitas
2012-Feb-03 16:45 UTC
Re: ruby on rails 3 tutorial book chapter9 Signin Failure
The problem here is that your user object, isn''t retrieving any objects on precisely this line: user = User.authenticate(params[:session][:email], params[:session][:password]) :) Exactly what you where trying to do when this happened? 2012/2/3 Jean <josorioe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Hi I have problem trying to pass the signin failure test. > > This is the test code of the sessions_controller.rb > > def create > user = User.authenticate(params[:session][:email], > params[:session][:password]) > if user.nil? > flash.now[:error] = "Invalid email/password combination." > @title = "Sign in" > render ''new'' > else > # Sign the user in and redirect to the user''s show page. > end > end > > If I check in my browser and clic on submit with all fields empty, I > get the following error: > > NoMethodError in SessionsController > #create undefined method `nil'' for nil:NilClass > > I check the book many times and I have code exactly as the book, but I > still have the error. Any help??? > > You can check the code in this link listing 9.8 > http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:signin_failure > > What I doing wrong? > > Thanks for any 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-/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. > >-- 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.
Well I tried two things. Go to localhost:3000/signin click on "sign in" button with out any information on email and password field, and I get this error. But if I fill the field with and user and password, that exist in my db I get the same error. And in the book at this time I suppost to see a flash error with something like a "invalid email/ password combination" but I get this error :s On Feb 3, 11:45 am, Aline de Oliveira Freitas <aline.do.frei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The problem here is that your user object, isn''t retrieving any objects on > precisely this line: > user = User.authenticate(params[:session][:email], > params[:session][:password]) > :) Exactly what you where trying to do when this happened? > > 2012/2/3 Jean <josor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > > > > > Hi I have problem trying to pass the signin failure test. > > > This is the test code of the sessions_controller.rb > > > def create > > user = User.authenticate(params[:session][:email], > > params[:session][:password]) > > if user.nil? > > flash.now[:error] = "Invalid email/password combination." > > @title = "Sign in" > > render ''new'' > > else > > # Sign the user in and redirect to the user''s show page. > > end > > end > > > If I check in my browser and clic on submit with all fields empty, I > > get the following error: > > > NoMethodError in SessionsController > > #create undefined method `nil'' for nil:NilClass > > > I check the book many times and I have code exactly as the book, but I > > still have the error. Any help??? > > > You can check the code in this link listing 9.8 > >http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:signin_fa... > > > What I doing wrong? > > > Thanks for any 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-/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.-- 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.
Dave Aronson
2012-Feb-03 16:53 UTC
Re: ruby on rails 3 tutorial book chapter9 Signin Failure
On Fri, Feb 3, 2012 at 11:37, Jean <josorioe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> NoMethodError in SessionsController > #create undefined method `nil'' for nil:NilClass > > I check the book many times and I have code exactly as the book, > but I still have the error. Any help???It is a bit odd. When we see "undefined method `some_method_name'' for nil:NilClass" that usually means that something was nil unexpectedly. This time though, the method called, according to the code, is "nil?", which does indeed exist on NilClass, and the code is indeed properly checking for a nil user. BUT... Then look a bit more closely at the error code. It''s gritching about "nil", not "nil?". Are you absolutely sure that the code you posted, is what is executing? Maybe you copied from the book into the post, but when you copied by hand from the book into your actual app, you forgot the question mark? That''s an easy thing to miss, especially if you''re not used to a question mark being a valid part of a method name. -Dave -- Dave Aronson: Available Cleared Ruby on Rails Freelancer (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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.
Dave Aronson
2012-Feb-03 16:56 UTC
Re: Re: ruby on rails 3 tutorial book chapter9 Signin Failure
On Fri, Feb 3, 2012 at 11:53, Jean <josorioe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> if I fill the field with and user and password, > that exist in my db I get the same error.That also sounds like a forgotten question mark. Ruby would try to call it, and fail, either way. -Dave -- Dave Aronson: Available Cleared Ruby on Rails Freelancer (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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.
No Dave, I copy from my code. And this is the error: NoMethodError in SessionsController#create undefined method `nil'' for nil:NilClass Rails.root: /Users/jeanosorio/rails_projects/sample_app Application Trace | Framework Trace | Full Trace app/models/user.rb:37:in `authenticate'' app/controllers/sessions_controller.rb:7:in `create'' Request Parameters: {"utf8"=>"✓", "authenticity_token"=>"1Dc0iARaC7tLF0Jwp7ZX9XJAOTtqHqavl0+x6qkHlEw=", "session"=>{"email"=>"", "password"=>"[FILTERED]"}, "commit"=>"Sign in"} And this is the code for user model def self.authenticate(email, submitted_password) user = find_by_email(email) return nil if user.nil return user if user.has_password?(summitted_password) end I don''t understand what''s happen On Feb 3, 11:56 am, Dave Aronson <googlegroups2d...-BRiZGj7G2yRXqviUI+FSNg@public.gmane.org> wrote:> On Fri, Feb 3, 2012 at 11:53, Jean <josor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > if I fill the field with and user and password, > > that exist in my db I get the same error. > > That also sounds like a forgotten question mark. Ruby would try to > call it, and fail, either way. > > -Dave > > -- > Dave Aronson: Available Cleared Ruby on Rails Freelancer > (NoVa/DC/Remote) -- seewww.DaveAronson.com, and blogs atwww.Codosaur.us,www.Dare2XL.com,www.RecruitingRants.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.
Prince Joseph
2012-Feb-03 17:33 UTC
Re: Re: ruby on rails 3 tutorial book chapter9 Signin Failure
def self.authenticate(email, submitted_password) user = find_by_email(email) return nil if user.nil return user if user.has_password?(summitted_password) end Here ''user.nil'' in the third line should be ''user.nil?''. There is a typo (''?'' missing). On Fri, Feb 3, 2012 at 10:43 PM, Jean <josorioe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No Dave, I copy from my code. And this is the error: > > NoMethodError in SessionsController#create > > undefined method `nil'' for nil:NilClass > Rails.root: /Users/jeanosorio/rails_projects/sample_app > > Application Trace | Framework Trace | Full Trace > app/models/user.rb:37:in `authenticate'' > app/controllers/sessions_controller.rb:7:in `create'' > Request > > Parameters: > > {"utf8"=>"✓", > "authenticity_token"=>"1Dc0iARaC7tLF0Jwp7ZX9XJAOTtqHqavl0+x6qkHlEw=", > "session"=>{"email"=>"", > "password"=>"[FILTERED]"}, > "commit"=>"Sign in"} > > > And this is the code for user model > > def self.authenticate(email, submitted_password) > user = find_by_email(email) > return nil if user.nil > return user if user.has_password?(summitted_password) > end > > I don''t understand what''s happen > > On Feb 3, 11:56 am, Dave Aronson <googlegroups2d...-BRiZGj7G2yRXqviUI+FSNg@public.gmane.org> > wrote: > > On Fri, Feb 3, 2012 at 11:53, Jean <josor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > if I fill the field with and user and password, > > > that exist in my db I get the same error. > > > > That also sounds like a forgotten question mark. Ruby would try to > > call it, and fail, either way. > > > > -Dave > > > > -- > > Dave Aronson: Available Cleared Ruby on Rails Freelancer > > (NoVa/DC/Remote) -- seewww.DaveAronson.com, and blogs atwww.Codosaur.us, > www.Dare2XL.com,www.RecruitingRants.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. > >-- Thanks, Prince -- 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.
Colin Law
2012-Feb-03 17:33 UTC
Re: Re: ruby on rails 3 tutorial book chapter9 Signin Failure
On 3 February 2012 17:13, Jean <josorioe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No Dave, I copy from my code. And this is the error: > > NoMethodError in SessionsController#create > > undefined method `nil'' for nil:NilClass > Rails.root: /Users/jeanosorio/rails_projects/sample_app > > Application Trace | Framework Trace | Full Trace > app/models/user.rb:37:in `authenticate'' > app/controllers/sessions_controller.rb:7:in `create'' > Request > > Parameters: > > {"utf8"=>"✓", > "authenticity_token"=>"1Dc0iARaC7tLF0Jwp7ZX9XJAOTtqHqavl0+x6qkHlEw=", > "session"=>{"email"=>"", > "password"=>"[FILTERED]"}, > "commit"=>"Sign in"} > > > And this is the code for user model > > def self.authenticate(email, submitted_password) > user = find_by_email(email) > return nil if user.nilRead the earlier posts from Dave carefully and look at the line above. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
OMG thank you soooo much!!! On Feb 3, 12:33 pm, Prince Joseph <pri...-LNT+Ry0jrSDQT0dZR+AlfA@public.gmane.org> wrote:> def self.authenticate(email, submitted_password) > user = find_by_email(email) > return nil if user.nil > return user if user.has_password?(summitted_password) > end > > Here ''user.nil'' in the third line should be ''user.nil?''. There is a typo > (''?'' missing). > > > > > > > > > > On Fri, Feb 3, 2012 at 10:43 PM, Jean <josor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > No Dave, I copy from my code. And this is the error: > > > NoMethodError in SessionsController#create > > > undefined method `nil'' for nil:NilClass > > Rails.root: /Users/jeanosorio/rails_projects/sample_app > > > Application Trace | Framework Trace | Full Trace > > app/models/user.rb:37:in `authenticate'' > > app/controllers/sessions_controller.rb:7:in `create'' > > Request > > > Parameters: > > > {"utf8"=>"✓", > > "authenticity_token"=>"1Dc0iARaC7tLF0Jwp7ZX9XJAOTtqHqavl0+x6qkHlEw=", > > "session"=>{"email"=>"", > > "password"=>"[FILTERED]"}, > > "commit"=>"Sign in"} > > > And this is the code for user model > > > def self.authenticate(email, submitted_password) > > user = find_by_email(email) > > return nil if user.nil > > return user if user.has_password?(summitted_password) > > end > > > I don''t understand what''s happen > > > On Feb 3, 11:56 am, Dave Aronson <googlegroups2d...-BRiZGj7G2yRXqviUI+FSNg@public.gmane.org> > > wrote: > > > On Fri, Feb 3, 2012 at 11:53, Jean <josor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > if I fill the field with and user and password, > > > > that exist in my db I get the same error. > > > > That also sounds like a forgotten question mark. Ruby would try to > > > call it, and fail, either way. > > > > -Dave > > > > -- > > > Dave Aronson: Available Cleared Ruby on Rails Freelancer > > > (NoVa/DC/Remote) -- seewww.DaveAronson.com, and blogs atwww.Codosaur.us, > >www.Dare2XL.com,www.RecruitingRants.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. > > -- > Thanks, > Prince-- 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.
Dave Aronson
2012-Feb-03 17:54 UTC
Re: Re: ruby on rails 3 tutorial book chapter9 Signin Failure
On Fri, Feb 3, 2012 at 12:13, Jean <josorioe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> And this is the code for user model > > def self.authenticate(email, submitted_password) > user = find_by_email(email) > return nil if user.nilAha! Right error, wrong place. Here''s where you''re missing the question mark. You had me worried that my awesome psychic powers were on the blink. ;-) -Dave -- Dave Aronson: Available Cleared Ruby on Rails Freelancer (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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.
LOL thanks Dave!! On Feb 3, 12:54 pm, Dave Aronson <googlegroups2d...-BRiZGj7G2yRXqviUI+FSNg@public.gmane.org> wrote:> On Fri, Feb 3, 2012 at 12:13, Jean <josor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > And this is the code for user model > > > def self.authenticate(email, submitted_password) > > user = find_by_email(email) > > return nil if user.nil > > Aha! Right error, wrong place. Here''s where you''re missing the > question mark. You had me worried that my awesome psychic powers were > on the blink. ;-) > > -Dave > > -- > Dave Aronson: Available Cleared Ruby on Rails Freelancer > (NoVa/DC/Remote) -- seewww.DaveAronson.com, and blogs atwww.Codosaur.us,www.Dare2XL.com,www.RecruitingRants.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.