Rails 4 - Titleize on read, downcase on save, in model -
i'm sure it's pretty dumb question can not figure out.
in user model have
`before_save :downcase_username` #because utilize custom subdomain each user request def downcase_username self.username = username.downcase end however, titleize username each time visible (read?) in view without specifying each time user.username.titleize. not know before_ phone call within model, in controller have utilize before_action. moreover, there way automate values of model ? (always titleize in view)
any hint appreciated.
thank much
you create custom getter...
class user < activerecord::base def username self[:username].titleize end end if want on reads views not on reads edits might improve off using decorator.
https://github.com/drapergem/draper
ruby-on-rails models
No comments:
Post a Comment