How to add a virtual attribute to a model in Ruby on Rails?

Ruby actually lets you create virtual attributes this way, which keeps you from having to manually create getter and setter methods:

attr_reader   :palindrome #getter
attr_writer   :palindrome #setter
attr_accessor :palindrome #both

You can also pass multiple arguments too:

attr_accessor :palindrome, :foo, :bar

The documentation for it isn’t the greatest.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)