Ruby on Rails has a way to view model properties
I am using NetBeans to build my first Ruby on Rails application. Is there a way that I can view all properties of the model? Should I just search the database?
I just use db/schema.rb
- seems to work fine for me.
You can call Model.attributes
in the Rails console. This gives a hash with all the attributes.
Be careful when using this inside your real code as it always recreates the hash and is therefore quite expensive.
You can use the annotate gem for this - it will add comments to the top of each model, specifying its properties.
Just type in the model name in the rails console and hit enter.
rails c # start your rails console
User
=> User(id: integer, email: string, password_digest: string...)
If anyone is looking at this and is using a newer version of Rails, you can simply call Model
in the console. (I'm on Rails 3.2.1 and Ruby 1.9.2p290.)
In fact, the call Model.attributes
does not work in this case.
A nice little tool that I use is MySQL. It's called MySQL Administrator .
This allows me to check that db (development / test / production), tables for db and finally columns (attributes).
Model.attributes #=> {'name' => 'foo', 'desc' => 'bar'}
PS www.railsbrain.com - use this.