GlyphGryph
GlyphGryph

Reputation: 4794

Ways to examine models/objects in Ruby on Rails?

I'm currently looking through a system trying to figure out how things work together - I know a couple basic ways to examine objects (I'm in the console), such as Object.methods, but I was wondering if there were ways to find, say, it's attributes, and it's relationships with other models (for example, has_many relationships) and the like.

Upvotes: 0

Views: 234

Answers (2)

yalestar
yalestar

Reputation: 9574

The Pry gem is awesome for this sort of thing.

Dig this Railscasts episode.

Upvotes: 3

lurker
lurker

Reputation: 58324

Sounds like you're referring to specifically an ActiveRecord object. If you look up the documentation on ActiveRecord (e.g., http://api.rubyonrails.org/classes/ActiveRecord/Base.html), you'll find a lot of methods to get some useful info. For example, to see the attributes, you could examine MyActiveRecord.attribute_names.

Upvotes: 0

Related Questions