From 8c8e5be9c97eaf7e88b0cefafdc191108c19d1b6 Mon Sep 17 00:00:00 2001 From: Aditya Kapoor Date: Sat, 5 Jul 2014 22:14:03 +0530 Subject: [PATCH] [ci skip] add guide for ActiveModel::Naming --- guides/source/active_model_basics.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index 0019d08328..1131a83c36 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -198,3 +198,26 @@ person.valid? # => true person.token = nil person.valid? # => raises ActiveModel::StrictValidationFailed ``` + +### ActiveModel::Naming + +Naming adds a number of class methods which make the naming and routing +easier to manage. The module defines the `model_name` class method which +will define a number of accessors using some `ActiveSupport::Inflector` methods. + +```ruby +class Person + extend ActiveModel::Naming +end + +Person.model_name.name # => "Person" +Person.model_name.singular # => "person" +Person.model_name.plural # => "people" +Person.model_name.element # => "person" +Person.model_name.human # => "Person" +Person.model_name.collection # => "people" +Person.model_name.param_key # => "person" +Person.model_name.i18n_key # => :person +Person.model_name.route_key # => "people" +Person.model_name.singular_route_key # => "person" +``` \ No newline at end of file