Guest User

Untitled

a guest
Apr 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. # If I want my title attribute to be made up of several other attributes,
  2. # how do you make it work for new records.
  3.  
  4. # E.g., this works for editing a record
  5. def title=(title)
  6. title = [date.year, date.month, date.day].compact.join('-') if title.blank?
  7. write_attribute(:title, title)
  8. end
  9.  
  10. # But for a new record, the date attribute doesn't exist yet
  11. # and the params are (without violating MVC) inaccessible.
  12.  
  13. # So what do you do?
Add Comment
Please, Sign In to add comment