data is storing in database when i had created but it is destroyed after the sign out

I had created users using devise in rails. I am storing user mobile number and land line number for the user profile, by using this code it is storing the cell and land line numbers in database but after the sign out it is not stored in the database. please tell me whats wrong in my code in users.rb

before_save :build_telephone   before_save :build_cell

validates :code, :presence => true, :numericality => true, :length => { :within => 1..2 }, :on => :update   validates :code2, :presence => true, :numericality => true, :length => { :within => 2..4 }, :on => :update   validates :number, :presence => true, :numericality => true, :length => { :within => 1..7 }, :on => :update   validates :code1, :presence => true, :numericality => true, :length => { :within => 1..2 }, :on => :update   validates :number1, :presence => true, :numericality => true, :length => {:minimum => 10, :maximum => 10}, :on => :update

attr_accessor :code,:code2, :number, :code1, :number1

attr_accessible :email, :password, :password_confirmation, :mobile, :landline, :remember_me , :code, :code2, :number, :code1, :number1

def build_cell       self.mobile = "#{self.code1}-#{self.number1}"     end

    def build_telephone       self.landline = "#{self.code}-#{self.code2}-#{self.number}"     end

Hi Kapil,

Please try with self.save in your methods build_cell & build_telephone.

Eg :

def build_cell    self.mobile = "#{self.code1}-#{self.number1}"    self.save end

Thanks,

Neethu

Hi,   Thanks for your quickest response, i had added the self.save but i am getting error as "stack level too deep" on submitting the profile form

Thanks, Kapil

Try following this thread, I have not it read completely. It may help you.

- Neethu

Try following this thread, I have not it read completely. It may help you.

- Neethu

I believe one of the validations is failing in the case where you update the user profile. Try using something with bang operator(like ‘save!’) in the code where you update the user profile (in the controller) to identify which validation is failing. (‘!’ will raise an exception if any validation is failed).

You should not add ‘self.save’ to the method, as you are calling these functions in ‘before_save’. It means these functions will be invoked before saving any object of that model. Calling ‘self.save’ inside it will result in an infinite loop.