Forum: Ruby on Rails Beginner Questions parameter passing failing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter Baldwin (Guest)
on 2006-01-07 19:09
(Received via mailing list)
Dear all,



I'm pretty much a complete programming novice, but I've battled my way
through

the Pickaxe book, and the Agile Rails book, and am trying to piece
together

some pretty basic functionality at the moment.



I'm having an issue passing parameters from a login form and would
really

appreciate some assistance. I suspect I've made some basic fundamental
error,

but I can't figure it out.



My "welcome" view page looks like this (my "welcome" action doesn't do
anything

but render the welcome view)



       <%= start_form_tag :action => :login %>

       <table>

            <tr>

                        <td> Enter your first name </td>

                        <td> <%= text_field :user, :firstname, 'size' =>
40
%> </td>



            <tr>

                        <td> </br> <%= submit_tag("Log In") %></td>



        <%= end_form_tag %>

        </table>





Which simply submits a firstname to my login action which tries to match
it
up

to an entry in my User model (which has firstname, lastname, email,
password
fields)



     def login

             @user = User.find_by_firstname(params[:firstname])

     end



However, when I try and display the resulting @user.firstname in the
login
view

I always get the following error.





   NoMethodError in Useradmin#login



   Showing app/views/useradmin/login.rhtml where line #4 raised:



   You have a nil object when you didn't expect it!

   The error occured while evaluating nil.firstname



This error appears even though the name submitted in the form matches
one in
the

database. The action works if I hard code the name instead of the

"params[:firstname]" text, so I think it's an issue with the parameters
passing.



Any assistance gratefully recieved.



Pete










---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.764 / Virus Database: 511 - Release Date: 15/09/2004
Joerg D. (Guest)
on 2006-01-07 19:14
Hi Peter,

Use @user = User.find_by_firstname(params[:user][:firstname])

Your forgot the [:user] bit.

Joerg
Joerg D. (Guest)
on 2006-01-07 19:14
Hi Peter,

Use @user = User.find_by_firstname(params[:user][:firstname])

You forgot the [:user] bit.

Joerg
Peter Baldwin (Guest)
on 2006-01-07 19:35
Thanks for that really quick response. Much appreciated.

Pete
This topic is locked and can not be replied to.