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?

+2


source to share


7 replies


I just use db/schema.rb

- seems to work fine for me.



+4


source


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.

+3


source


You can use the annotate gem for this - it will add comments to the top of each model, specifying its properties.

+3


source


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...)

      

+3


source


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.

+1


source


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).

0


source


Model.attributes #=> {'name' => 'foo', 'desc' => 'bar'}

      

PS www.railsbrain.com - use this.

0


source







All Articles