What’s the proper way to initialize a class_attribute in Rails?
I am using this:
class Foo < ActiveRecord::Base
class_attribute :foobar
self.foobar = []
# ...
end
Which seems to work fine, but also seems to look a bit non-Railsy to me.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Everything is described here: http://apidock.com/rails/Class/class_attribute
If you click on “Show source” you will see there are no options available to set default value. You are doing it right.