When I enter the name of a ActiveRecord class to irb, the schema of the record is displayed:
Art Art(id: integer, name: string, created_at: datetime, updated_at: datetime)
How to query that vir ruby code?
When I enter the name of a ActiveRecord class to irb, the schema of the record is displayed:
Art Art(id: integer, name: string, created_at: datetime, updated_at: datetime)
How to query that vir ruby code?
When I enter the name of a ActiveRecord class to irb, the schema of the record is displayed:
How to query that vir ruby code?
e.g.
Author
=> Authorid: integer, first_name: string, last_name: string, dob: date, created_at: datetime, updated_at: datetime, genre: string
Author.inspect
=> "Author(id: integer, first_name: string, last_name: string, dob: date, created_at: datetime, updated_at: datetime, genre: string)"
HTH,
When I enter the name of a ActiveRecord class to irb, the schema of the record is displayed:
Art Art(id: integer, name: string, created_at: datetime, updated_at: datetime)
How to query that vir ruby code?
Take a peak at Art.columns
Fred
Thanks for your replies.
Using columns, the name can be queried by human_name:
Art.columns[0].human_name
inspect is perfect for displaying purposes.
Fritz Trapper wrote:
Thanks for your replies.
Using columns, the name can be queried by human_name:
Art.columns[0].human_name
inspect is perfect for displaying purposes.
Note that, in my experience at least, this is rarely necessary unless you're writing something like ActiveScaffold. What are you trying for here?
Best,