Forum: Ruby on Rails Is there a utility tool to check the convention between DB t

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
allen (Guest)
on 2007-04-09 06:34
(Received via mailing list)
Say that I could just enter the AR model's name, and it will output
the DB table's name according to rails' default convention. Thanks.
Jeremy McAnally (Guest)
on 2007-04-09 07:28
(Received via mailing list)
The tableize method will return the table-convention-version of a
string; this means you could do something like the following:

def table_name(model)
  model.to_s.tableize   # stringify a class name and tableize it
end

table_name(User)
>> users
table_name(Session)
>> sessions
table_name(TeamMember)
>> team_members

--Jeremy

On 4/8/07, allen <removed_email_address@domain.invalid> wrote:
>
> Say that I could just enter the AR model's name, and it will output
> the DB table's name according to rails' default convention. Thanks.
>
>
> >
>


--
http://www.jeremymcanally.com/

My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
allen (Guest)
on 2007-04-09 07:52
(Received via mailing list)
Thanks a lot!

On Apr 9, 11:27 am, "Jeremy McAnally" <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.