How can you discover accessible attribute names from a model instance?


<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?


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


  • Can't configure nginx as a proxy for tomcat with context path
  • Browserify and Reactify source maps include full local path names
  • Does “internal” visibility modifier in Kotlin work yet?
  • Access the state of control in Winforms from another application
  • Mercurial: Identify file name after rename
  • WARNING:root:Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER. Wit
  • How to display a tooltip according to mouse position? - JavaFX
  • Watson Conversation - Why is the ANYTHING ELSE node not chosen
  • Merge Module leaving files during uninstall
  • Connecting bluetooth device to windows phone 8 application
  • Compress a file with GZipStream while maintaining its meta-data
  • Is there a way to dynamically embed PDF Files in a JSP pulled from the file system?
  • How do I remove all but some records based on a threshold?
  • Android device acting as an accessory
  • Implicit joins and Where in Doctrine - how?
  • I18n locale disregarding fallbacks
  • converting text file into xml using php?
  • Installed module is empty
  • Refering to the class itself from within a class mehod in Objective C
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • Highlight one bar in a series in highcharts?
  • Jquery - Jquery Wysiwyg return html as a string
  • Akka Routing: Reply's send to router ends up as dead letters
  • Calling of Constructors in a Java
  • AT Commands to Send SMS not working in Windows 8.1
  • Arrays break string types in Julia
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • PHP: When would you need the self:: keyword?
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • WPF Applying a trigger on binding failure
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How do I configure my settings file to work with unit tests?
  • Java static initializers and reflection
  • Is it possible to post an object from jquery to bottle.py?
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app