30632

Question:
<a href="https://stackoverflow.com/a/1291395/414825" rel="nofollow">This answer</a> says you can do object.attribute_names
to get a list of attribute names for a model instance.
But is there any way to get a list of all its <em>accessible</em> attribute names?
Answer1:You can use <strong><a href="http://apidock.com/rails/ActiveModel/MassAssignmentSecurity/ClassMethods/accessible_attributes" rel="nofollow">accessible_attributes
</a></strong>.
You have to provide a role, because different roles can have different accessible attributes.
If you want to have the attributes from a model instance you can use this code:
@my_model.class.accessible_attributes(:admin) # Returns array of symbols