Ruby on Rails model field updates through console, not through browser -
i noticed 1 of model fields not update through app in browser after had been set. when went investigate discovered field declared through custom validator:
validate :amount_validator def amount_validator if self.amount == nil errors.add(:amount, "please fill in amount.") end end
i thought issue missing:
validates :amount, presence: true
i added still couldn't update field through browser. when saved value , page refreshed had reverted original value. read question indicated should try updating field through console , see if there errors. did this, worked no errors. went browser , value had changed still not update through browser. help.
depending on rails version you're using, error might around accessible attributes (rails 3) or strong paramenters (rails 4).
on rails 3, make sure have in model:
attr_accessible :amount
on rails 4, make sure allowing attribute in hash pass update_attributes
in controller:
your_model.update_attributes(params.require(:your_model_name).permit([:amount]))
Comments
Post a Comment