I''m using Rails Recipes to create a login form but instead of username and password, my setup is firstname, lastname, password. I seemed to be gramatically challenged and not sure how to set up the parameter list. Can anyone offer up a suggestion. The book shows the method starting like: if request.post? user = User.find(:first, :conditions => [''username = ?'' , params[:username]]) So here is my attempt but with some obvious mistakes: def login if request.post? user = User.find(:first, :conditions => [''first_name = ?'', ''last_name = ?'', params [:first_name], [last_name] ..... end TIA Stuart
I''m now getting a wrong number of arguments (2 for 1). Again, the user should sign on with first name , last name, password def login if request.post? user = User.find(:first, :conditions => [''first_name = ?'', ''last_name = ?'', params[:first_name, :last_name]]) if user.blank? || Digest::SHA256.hexdigest(params[:password] + user.password_salt) ! user.password_hash raise "First name, Last name, or password invalid" end session[:user] = user.id redirect_to :action => session[:intended_action], :controller => session[:intended_controller] end end Stuart On 8/7/06, Dark Ambient <sambient@gmail.com> wrote:> I''m using Rails Recipes to create a login form but instead of username > and password, my setup is firstname, lastname, password. > > I seemed to be gramatically challenged and not sure how to set up the > parameter list. Can anyone offer up a suggestion. > The book shows the method starting like: > > if request.post? > user = User.find(:first, :conditions => [''username = ?'' , params[:username]]) > > So here is my attempt but with some obvious mistakes: > def login > if request.post? > user = User.find(:first, :conditions => [''first_name = ?'', > ''last_name = ?'', params > [:first_name], > [last_name] > > ..... > end > > TIA > Stuart >
user = User.find(:first, :conditions => [''first_name = ? and last_name = ?'', params[:first_name], params[:last_name]) On 8/7/06, Dark Ambient <sambient@gmail.com> wrote:> I''m now getting a wrong number of arguments (2 for 1). > Again, the user should sign on with first name , last name, password > > def login > if request.post? > user = User.find(:first, :conditions => [''first_name = ?'', > ''last_name = ?'', > params[:first_name, :last_name]]) > if user.blank? || > Digest::SHA256.hexdigest(params[:password] + user.password_salt) !> user.password_hash > raise "First name, Last name, or password invalid" > end > session[:user] = user.id > redirect_to :action => session[:intended_action], > :controller => session[:intended_controller] > end > end > > Stuart > > On 8/7/06, Dark Ambient <sambient@gmail.com> wrote: > > I''m using Rails Recipes to create a login form but instead of username > > and password, my setup is firstname, lastname, password. > > > > I seemed to be gramatically challenged and not sure how to set up the > > parameter list. Can anyone offer up a suggestion. > > The book shows the method starting like: > > > > if request.post? > > user = User.find(:first, :conditions => [''username = ?'' , params[:username]]) > > > > So here is my attempt but with some obvious mistakes: > > def login > > if request.post? > > user = User.find(:first, :conditions => [''first_name = ?'', > > ''last_name = ?'', params > > [:first_name], > > [last_name] > > > > ..... > > end > > > > TIA > > Stuart > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Try User.find(:first, :conditions => [''first_name = ? AND last_name = ?'', params[:first_name], params[:last_name]) Jon On 7 Aug 2006, at 16:33, Dark Ambient wrote:> I''m now getting a wrong number of arguments (2 for 1). > Again, the user should sign on with first name , last name, password > > def login > if request.post? > user = User.find(:first, :conditions => [''first_name = ?'', > ''last_name = ?'', > params[:first_name, :last_name]]) > if user.blank? || > Digest::SHA256.hexdigest(params[:password] + > user.password_salt) !> user.password_hash > raise "First name, Last name, or password invalid" > end > session[:user] = user.id > redirect_to :action => session[:intended_action], > :controller => session[:intended_controller] > end > end > > Stuart > > On 8/7/06, Dark Ambient <sambient@gmail.com> wrote: >> I''m using Rails Recipes to create a login form but instead of >> username >> and password, my setup is firstname, lastname, password. >> >> I seemed to be gramatically challenged and not sure how to set up the >> parameter list. Can anyone offer up a suggestion. >> The book shows the method starting like: >> >> if request.post? >> user = User.find(:first, :conditions => [''username = ?'' , params >> [:username]]) >> >> So here is my attempt but with some obvious mistakes: >> def login >> if request.post? >> user = User.find(:first, :conditions => [''first_name = ?'', >> ''last_name = ?'', >> params >> [:first_name], >> [last_name] >> >> ..... >> end >> >> TIA >> Stuart >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thank you , that fixed it! Stuart On 8/7/06, Jonathan del Strother <maillist@steelskies.com> wrote:> Try > User.find(:first, :conditions => [''first_name = ? AND last_name = ?'', > params[:first_name], params[:last_name]) > > Jon > > > On 7 Aug 2006, at 16:33, Dark Ambient wrote: > > > I''m now getting a wrong number of arguments (2 for 1). > > Again, the user should sign on with first name , last name, password > > > > def login > > if request.post? > > user = User.find(:first, :conditions => [''first_name = ?'', > > ''last_name = ?'', > > params[:first_name, :last_name]]) > > if user.blank? || > > Digest::SHA256.hexdigest(params[:password] + > > user.password_salt) !> > user.password_hash > > raise "First name, Last name, or password invalid" > > end > > session[:user] = user.id > > redirect_to :action => session[:intended_action], > > :controller => session[:intended_controller] > > end > > end > > > > Stuart > > > > On 8/7/06, Dark Ambient <sambient@gmail.com> wrote: > >> I''m using Rails Recipes to create a login form but instead of > >> username > >> and password, my setup is firstname, lastname, password. > >> > >> I seemed to be gramatically challenged and not sure how to set up the > >> parameter list. Can anyone offer up a suggestion. > >> The book shows the method starting like: > >> > >> if request.post? > >> user = User.find(:first, :conditions => [''username = ?'' , params > >> [:username]]) > >> > >> So here is my attempt but with some obvious mistakes: > >> def login > >> if request.post? > >> user = User.find(:first, :conditions => [''first_name = ?'', > >> ''last_name = ?'', > >> params > >> [:first_name], > >> [last_name] > >> > >> ..... > >> end > >> > >> TIA > >> Stuart > >> > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Actually I should ask another question, in the recipes book the login form is built with start_form_tag, so: <%= start_form_tag :action => "signin" %> <label for="username" >Username:</label> <%= text_field_tag "username" %><br /> <label for="password" >Password:</label> <%= password_field_tag "password" %><br /> <%= submit_tag "Sign in" %> <%= end_form_tag %> I am using a regular form tag , wondering if that would make a different how the post is handled? Here is the way I constructed the form: <form action="login" method="post"> <fieldset> <legend>Log in to your account </legend> <label for="firt_name" >First name:</label> <%= text_field "user", "first_name" %> <label for="last_name" >Last name:</label> <%= text_field "user", "last_name" %> <label for="password" >Password:</label> <%= password_field "user", "password" %> <input type="Submit" value="Login" %> </form> </fieldset> Stuart On 8/7/06, Dark Ambient <sambient@gmail.com> wrote:> Thank you , that fixed it! > > Stuart > > On 8/7/06, Jonathan del Strother <maillist@steelskies.com> wrote: > > Try > > User.find(:first, :conditions => [''first_name = ? AND last_name = ?'', > > params[:first_name], params[:last_name]) > > > > Jon > > > > > > On 7 Aug 2006, at 16:33, Dark Ambient wrote: > > > > > I''m now getting a wrong number of arguments (2 for 1). > > > Again, the user should sign on with first name , last name, password > > > > > > def login > > > if request.post? > > > user = User.find(:first, :conditions => [''first_name = ?'', > > > ''last_name = ?'', > > > params[:first_name, :last_name]]) > > > if user.blank? || > > > Digest::SHA256.hexdigest(params[:password] + > > > user.password_salt) !> > > user.password_hash > > > raise "First name, Last name, or password invalid" > > > end > > > session[:user] = user.id > > > redirect_to :action => session[:intended_action], > > > :controller => session[:intended_controller] > > > end > > > end > > > > > > Stuart > > > > > > On 8/7/06, Dark Ambient <sambient@gmail.com> wrote: > > >> I''m using Rails Recipes to create a login form but instead of > > >> username > > >> and password, my setup is firstname, lastname, password. > > >> > > >> I seemed to be gramatically challenged and not sure how to set up the > > >> parameter list. Can anyone offer up a suggestion. > > >> The book shows the method starting like: > > >> > > >> if request.post? > > >> user = User.find(:first, :conditions => [''username = ?'' , params > > >> [:username]]) > > >> > > >> So here is my attempt but with some obvious mistakes: > > >> def login > > >> if request.post? > > >> user = User.find(:first, :conditions => [''first_name = ?'', > > >> ''last_name = ?'', > > >> params > > >> [:first_name], > > >> [last_name] > > >> > > >> ..... > > >> end > > >> > > >> TIA > > >> Stuart > > >> > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
I guess it does make a difference because with start_form_tag the form works. :) Thanks Stuart On 8/7/06, Dark Ambient <sambient@gmail.com> wrote:> Actually I should ask another question, in the recipes book the login > form is built with > start_form_tag, so: > <%= start_form_tag :action => "signin" %> > <label for="username" >Username:</label> > <%= text_field_tag "username" %><br /> > <label for="password" >Password:</label> > <%= password_field_tag "password" %><br /> > <%= submit_tag "Sign in" %> > <%= end_form_tag %> > > I am using a regular form tag , wondering if that would make a > different how the post is handled? > Here is the way I constructed the form: > > <form action="login" method="post"> > <fieldset> > <legend>Log in to your account > </legend> > <label for="firt_name" >First name:</label> > <%= text_field "user", "first_name" %> > > <label for="last_name" >Last name:</label> > <%= text_field "user", "last_name" %> > > <label for="password" >Password:</label> > <%= password_field "user", "password" %> > > <input type="Submit" value="Login" %> > </form> > </fieldset> > > Stuart > On 8/7/06, Dark Ambient <sambient@gmail.com> wrote: > > Thank you , that fixed it! > > > > Stuart > > > > On 8/7/06, Jonathan del Strother <maillist@steelskies.com> wrote: > > > Try > > > User.find(:first, :conditions => [''first_name = ? AND last_name = ?'', > > > params[:first_name], params[:last_name]) > > > > > > Jon > > > > > > > > > On 7 Aug 2006, at 16:33, Dark Ambient wrote: > > > > > > > I''m now getting a wrong number of arguments (2 for 1). > > > > Again, the user should sign on with first name , last name, password > > > > > > > > def login > > > > if request.post? > > > > user = User.find(:first, :conditions => [''first_name = ?'', > > > > ''last_name = ?'', > > > > params[:first_name, :last_name]]) > > > > if user.blank? || > > > > Digest::SHA256.hexdigest(params[:password] + > > > > user.password_salt) !> > > > user.password_hash > > > > raise "First name, Last name, or password invalid" > > > > end > > > > session[:user] = user.id > > > > redirect_to :action => session[:intended_action], > > > > :controller => session[:intended_controller] > > > > end > > > > end > > > > > > > > Stuart > > > > > > > > On 8/7/06, Dark Ambient <sambient@gmail.com> wrote: > > > >> I''m using Rails Recipes to create a login form but instead of > > > >> username > > > >> and password, my setup is firstname, lastname, password. > > > >> > > > >> I seemed to be gramatically challenged and not sure how to set up the > > > >> parameter list. Can anyone offer up a suggestion. > > > >> The book shows the method starting like: > > > >> > > > >> if request.post? > > > >> user = User.find(:first, :conditions => [''username = ?'' , params > > > >> [:username]]) > > > >> > > > >> So here is my attempt but with some obvious mistakes: > > > >> def login > > > >> if request.post? > > > >> user = User.find(:first, :conditions => [''first_name = ?'', > > > >> ''last_name = ?'', > > > >> params > > > >> [:first_name], > > > >> [last_name] > > > >> > > > >> ..... > > > >> end > > > >> > > > >> TIA > > > >> Stuart > > > >> > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > >
Stuart Fellowes wrote:> I guess it does make a difference because with start_form_tag the form > works. :) > > Thanks > StuartYou can always View Source from your browser to see what''s different between the two approaches. Jeff -- Posted via http://www.ruby-forum.com/.
Good idea, I forgot that option. Stuart On 8/7/06, Jeff Cohen <cohen.jeff@gmail.com> wrote:> Stuart Fellowes wrote: > > I guess it does make a difference because with start_form_tag the form > > works. :) > > > > Thanks > > Stuart > > You can always View Source from your browser to see what''s different > between the two approaches. > > Jeff > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >