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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060107/1217f202/attachment-0001.html
Joerg Diekmann
2006-Jan-07 17:14 UTC
[Rails] Re: Beginner Questions parameter passing failing
Hi Peter, Use @user = User.find_by_firstname(params[:user][:firstname]) Your forgot the [:user] bit. Joerg -- Posted via http://www.ruby-forum.com/.
Joerg Diekmann
2006-Jan-07 17:14 UTC
[Rails] Re: Beginner Questions parameter passing failing
Hi Peter, Use @user = User.find_by_firstname(params[:user][:firstname]) You forgot the [:user] bit. Joerg -- Posted via http://www.ruby-forum.com/.