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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Aug-12 17:00 UTC
Re: How to query the schema of a ActiveRecord class?
On Thu, Aug 12, 2010 at 9:48 AM, Fritz Trapper <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-12 17:04 UTC
Re: How to query the schema of a ActiveRecord class?
On Aug 12, 12:48 pm, Fritz Trapper <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-13 19:37 UTC
Re: How to query the schema of a ActiveRecord class?
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, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.