0

This question is about ruby on rails. What is the way to get the list of all keys that I can pass to a ruby on rails model's constructor? post.attributes method gives me the list of all actual columns in that table. But it doesn't include fields generated by associations. It would not include :blog. How can I attributes plus fields created by association? Thanks.

1 Answers1

0

There are many ways to check the attributes of Model:

  1. Model => return Model fields with their datatype
  2. Model.new => return Model fields with their default values
  3. Model.inspect => return string of Model fields with their datatype
  4. Model.attribute_names => returns array of attributes
  5. Model.column_names => returns array of attributes
  6. Model.new.attributes => return hash of all fields with default values
puneet18
  • 4,341
  • 2
  • 21
  • 27