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@googlegroups.com.
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.

Search Discussions

  • Aline de Oliveira Freitas at Feb 3, 2012 at 4:45 pm
    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@gmail.com>
    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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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.
  • Jean at Feb 3, 2012 at 4:53 pm
    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
    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...@gmail.com>






    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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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 at Feb 3, 2012 at 4:57 pm

    On Fri, Feb 3, 2012 at 11:53, Jean 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@googlegroups.com.
    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.
  • Jean at Feb 3, 2012 at 5:13 pm
    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 wrote:
    On Fri, Feb 3, 2012 at 11:53, Jean 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@googlegroups.com.
    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 at Feb 3, 2012 at 5:34 pm
    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 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 wrote:
    On Fri, Feb 3, 2012 at 11:53, Jean 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@googlegroups.com.
    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.

    --
    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@googlegroups.com.
    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.
  • Jean at Feb 3, 2012 at 5:36 pm
    OMG thank you soooo much!!!
    On Feb 3, 12:33 pm, Prince Joseph 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 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...@davearonson.com>
    wrote:
    On Fri, Feb 3, 2012 at 11:53, Jean 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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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 at Feb 3, 2012 at 5:34 pm

    On 3 February 2012 17:13, Jean 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
    Read 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@googlegroups.com.
    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 at Feb 3, 2012 at 5:55 pm

    On Fri, Feb 3, 2012 at 12:13, Jean 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) -- 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@googlegroups.com.
    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.
  • Jean at Feb 3, 2012 at 8:30 pm
    LOL thanks Dave!!
    On Feb 3, 12:54 pm, Dave Aronson wrote:
    On Fri, Feb 3, 2012 at 12:13, Jean 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@googlegroups.com.
    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 at Feb 3, 2012 at 4:54 pm

    On Fri, Feb 3, 2012 at 11:37, Jean 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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 3, '12 at 4:37p
activeFeb 3, '12 at 8:30p
posts11
users5
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase