diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2014-07-06 16:44:34 +0200 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2014-07-06 16:44:34 +0200 |
commit | faf7e39744ee1adf0e581ed0278234173c5bd771 (patch) | |
tree | 7078089c9db773e1bcd9127c5c93ac8463fa7799 /guides/source | |
parent | e972d341209f64d1599e30a36b82eee2aa4cd553 (diff) | |
parent | 8c8e5be9c97eaf7e88b0cefafdc191108c19d1b6 (diff) | |
download | rails-faf7e39744ee1adf0e581ed0278234173c5bd771.tar.gz rails-faf7e39744ee1adf0e581ed0278234173c5bd771.tar.bz2 rails-faf7e39744ee1adf0e581ed0278234173c5bd771.zip |
Merge pull request #15958 from aditya-kapoor/active-model-naming-guide
[ci skip] add guide for ActiveModel::Naming
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_model_basics.md | 23 |
1 files changed, 23 insertions, 0 deletions
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 |