Hi, Still from yesterday trying to get things to work, rails doesn''t seems to get things very clear, I made signup.rhtml which looks like this: <%= error_messages_for :user %> <%= form_tag :action => "signup" %> <dl> <dt>Desired username</dt> <dd><%= text_field "user", "username", "size" => 20 %></dd> <dt>Email address</dt> <dd><%= text_field "user", "email", "size" => 20 %></dd> <dt>Choose a password</dt> <dd><%= password_field "user", "password", "size" => 20 %></dd> <dt>Re-enter password</dt> <dd><%= password_field "user", "confirm", "size" => 20 %></dd> <dt></dt> <dd><%= submit_tag "Log in", :name=>"login", :class=>"submit" %> </dd> </dl> <%= end_form_tag %> And then I want to validate if username is empty, email is valid email, and password is the same as confirm password, but things are not working like it should.... here is my controller.. def signup if request.post? @user = User.new(:username => params[:user][:username]) if @user.save redirect_to :action => ''login'' else @method = ''not saved''; end end end This givfes me an error (undefined method `confirm'' for #<User:0x47f75e8>), this looks ugly and doesn''t describe anything to me :S:S:S:S Can somebody help here, rails is giving me too much pain...I thought it was more simple then this? -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 16, 2007, at 2:53 PM, Jamal Soueidan wrote:> And then I want to validate if username is empty, email is valid > email, > and password is the same as confirm password, but things are not > working > like it should.... > > .... > Can somebody help here, rails is giving me too much pain...I > thought it > was more simple then this?Hi Jamal, I think you just add a validate method to your class and add the error in there if the 2 don''t match. I found this code from the rails list archive. Maybe it will help you.> class Model < ActiveRecord::Base > attr_accessor :password, :password_confirmation > > def validate > errors.add(''password'', ''Password and confirmation do not match'') > unless password_confirmation == password > end > > def before_save > self.password_sha1 = Digest::SHA1(password) if password > end > endfrom http://wrath.rubyonrails.org/pipermail/rails/2004-November/000587.html --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> Hi, > > Still from yesterday trying to get things to work, rails doesn''t seems > to get things very clear, I made signup.rhtml which looks like this: > > <dt>Re-enter password</dt> > <dd><%= password_field "user", "confirm", "size" => 20 %></dd> > > This givfes me an error (undefined method `confirm'' for > #<User:0x47f75e8>), this looks ugly and doesn''t describe anything to me > :S:S:S:SThe form helpers trying access a particular model object to show the current value of that object. For instance: <%= text_field ''post'', ''title'' %> Will try to get "@post.title" as the calue that will load in the text field. So when you try to do the above password field, rails tries to get the value of "@user.confirm". The problem is your User class has no method or DB field named "confirm", and it generates a no method error. To do this do two things #model class User < ActiveRecord::Base #this will give your model a "password_confirmation" attribute validates_confirmation_of :password end #view <%= password_field ''user'', ''password_confirmation'' %>> And then I want to validate if username is empty, email is valid email, > and password is the same as confirm password, but things are not working > like it should....#model class User < ActiveRecord::Base validates_presence_of :username validates_format_of :email, :with => /some regex/ validates_confirmation_of :password end -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> Jamal Soueidan wrote: >> Hi, >> >> Still from yesterday trying to get things to work, rails doesn''t seems >> to get things very clear, I made signup.rhtml which looks like this: > > Will try to get "@post.title" as the calue that will load in the text > field. So when you try to do the above password field, rails tries to > get the value of "@user.confirm". The problem is your User class has no > method or DB field named "confirm", and it generates a no method error.Thank you very much :) it worked... -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---