Ruby on Rails Sunday, January 29, 2012

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

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment