I have a 20 field database, and would like to set all the variables to be able to be accessed.
Is there a way to set attr_accessor to all of the variables, without listing each one i.e.
attr_accesor :a, :b, … etc
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.
attr_accessoris for adding get/set methods on a plain ruby object. With an ActiveRecord model, these are created automatically based on the columns in your schema.Normally all ActiveRecord attributes are “accessible” which means you can mass-assign values to all of them from the params hash:
Model.update_attributes(params[:model])You might be thinking of
attr_accessiblewhich makes only certain columns accessible this way, and makes the rest “protected”, so they can only be assigned directly through their setter method.The opposite is
attr_protectedwhich leaves all columns accessible except the ones you specify.