Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get plural version of Rails model name

Let's say I have an ActiveRecord model called PaymentMilestone.

Is there a good way to get payment_milestones out of that?

(I know #table_name can kind of do that, but my table name is payment_milestone (singular), not payment_milestones, and I need the plural version.)

like image 951
Jason Swett Avatar asked Feb 03 '14 19:02

Jason Swett


2 Answers

A few method calls, but this works:

> PaymentMilestone.name.underscore.pluralize
=> "payment_milestones"
like image 54
vee Avatar answered Nov 09 '22 23:11

vee


PaymentMilestone.model_name.plural

like image 20
Andreas Baumgart Avatar answered Nov 09 '22 23:11

Andreas Baumgart