I’m pretty much a complete programming novice, but I’ve battled my way
the Pickaxe book, and the Agile Rails book, and am trying to piece
some pretty basic functionality at the moment.
I’m having an issue passing parameters from a login form and would
appreciate some assistance. I suspect I’ve made some basic fundamental
but I can’t figure it out.
My “welcome” view page looks like this (my “welcome” action doesn’t do
but render the welcome view)
<%= start_form_tag :action => :login %> <table> <tr> <td> Enter your first name </td> <td> <%= text_field :user, :firstname, 'size' =>
<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
to an entry in my User model (which has firstname, lastname, email,
def login @user = User.find_by_firstname(params[:firstname]) end
However, when I try and display the resulting @user.firstname in the
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
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
Any assistance gratefully recieved.
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