ruby-on-railsactiverecord

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


Solution

  • A few method calls, but this works:

    > PaymentMilestone.name.underscore.pluralize
    => "payment_milestones"