I have a Plain Old Ruby Class (PORO) that behaves a lot like an ActiveRecord model, although it is not persisted to the database.
To make the internationalization(I18n) as painlessly as possible, I would like to also use the SomeModel.model_name.human
and SomeModel.human_attribute_name(:attribute)
methods on this PORO.
What module do I need to include to include above methods on my PORO?
What is ActiveRecord? ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code. When you need to make changes to the database, you'll write Ruby code, and then run "migrations" which makes the actual changes to the database.
1.2 Object Relational Mapping Object Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system.
ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.
Extend your class with the ActiveModel::Translation
module:
class Widget
extend ActiveModel::Translation
end
Widget.model_name.human
=> "Widget"
Widget.human_attribute_name :my_attribute
=> "My attribute"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With