On Monday, July 30, 2012 6:16:47 AM UTC+1, Sumit Srivastava wrote: > > So I updated the method as follows, > > def passwordtext=(pass) >> @password1=pass >> self.salt = SecureRandom.hex(10) if !self.salt? >> self.password = User.encrypt(@password1, self.salt) >> end >> > > And added a attr_accessor named as passwordtext. Also I renamed the > password_field_tag in the view as "passwordtext". Doing this didn't help at > all as the passwordtext method didn't execute. > > So, the problem how should I rename my variables to make it work. > > Not sure what you mean by 'didn't execute' but the instance variable you set should be @passwordtext if that's the name you gave attr_accessor. You also want to make sure you passwordtext= method is defined after the call to attr_accessor
Fred > Regards > Sumit Srivastava > > The power of imagination makes us infinite... > > > On 29 July 2012 14:47, Frederick Cheung <frederick.che...@gmail.com>wrote: > >> >> >> On Friday, July 27, 2012 11:52:26 AM UTC+1, Sumit Srivastava wrote: >>> >>> >>> Tom, >>> That might be another solution. But what I am trying to know is why >>> isn't this method working. And how is the action *def password=(pass) >>> *actually >>> being called. Because I didn't see any exclusive line where it is being >>> called. My analysis says it is being executed because of the * >>> attr_accessor* and having name same as that of the column *password. >>> * * >>> * >> >> *Am I right? >>> >>> * >> >> It's hard to say because it's extremely hard to piece together what code >> exactly is excuting - seems like there's at least 3 different versions in >> this thread, but it sounds to me like you've >> definte a password= method always calls self.password= which (by >> definition) calls your password= method and so you end up in an infinite >> recursion. >> The original tutorial you followed used a different name for the >> attribute so instead of calling self.password they were calling >> self.hashed_password= instead. You could either follow the tutorial >> (although as others have pointed it, it is really old (Rails 3.2has >> a has_secure_password that handles this) or use >> self.write_attribute(:password, some_value) when you want to store the >> hashed value >> >> >> Fred >> >> >>> **Regards >>> Sumit Srivastava >>> >>> The power of imagination makes us infinite... >>> >>> >>> On 27 July 2012 16:12, Michael Pavling <pavl...@gmail.com> wrote: >>> >>>> On 27 July 2012 11:37, sumit srivastava <sumit.theinvinci...@gmail.com* >>>> *> wrote: >>>> > This is what I receive, >>>> > >>>> > SystemStackError (stack level too deep): >>>> > app/models/user.rb:26:in `password=' >>>> > app/models/user.rb:27:in `password=' >>>> > app/controllers/user_**controller.rb:31:in `new' >>>> > app/controllers/user_**controller.rb:31:in `createuser' >>>> > >>>> > Here createuser action is used to store the user info into database. >>>> > >>>> > Line 31 reads as follows, >>>> > @user = User.new(params[:user]) >>>> >>>> I would put a breakpoint on that line and then keep stepping into >>>> until you see where it's looping :-/ >>>> >>>> -- >>>> 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@googlegroups.** >>>> com <rubyonrails-talk@googlegroups.com>. >>>> To unsubscribe from this group, send email to >>>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com> >>>> . >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> -- >> 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@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/Ed2oQol364oJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ciXDKwGTLKQJ. For more options, visit https://groups.google.com/groups/opt_out.