singular

singular(record_or_class) Class Public methods Returns the singular class name of a record or class. ActiveModel::Naming.singular(post) # => "post" ActiveModel::Naming.singular(Highrise::Person) # => "highrise_person"

singular_route_key

singular_route_key(record_or_class) Class Public methods Returns string to use while generating route names. It differs for namespaced models regarding whether it's inside isolated engine. # For isolated engine: ActiveModel::Naming.singular_route_key(Blog::Post) # => "post" # For shared engine: ActiveModel::Naming.singular_route_key(Blog::Post) # => "blog_post"

uncountable?

uncountable?(record_or_class) Class Public methods Identifies whether the class name of a record or class is uncountable. ActiveModel::Naming.uncountable?(Sheep) # => true ActiveModel::Naming.uncountable?(Post) # => false

model_name

model_name() Instance Public methods Returns an ActiveModel::Name object for module. It can be used to retrieve all kinds of naming-related information (See ActiveModel::Name for more information). class Person < ActiveModel::Model end Person.model_name # => Person Person.model_name.class # => ActiveModel::Name Person.model_name.singular # => "person" Person.model_name.plural # => "people"

has_secure_password

has_secure_password(options = {}) Instance Public methods Adds methods to set and authenticate against a BCrypt password. This mechanism requires you to have a password_digest attribute. Validations for presence of password on create, confirmation of password (using a password_confirmation attribute) are automatically added. If you wish to turn off validations, pass validations: false as an argument. You can add more validations by hand if need be. If you don't need the confirmatio

authenticate

authenticate(unencrypted_password) Instance Public methods Returns self if the password is correct, otherwise false. class User < ActiveRecord::Base has_secure_password validations: false end user = User.new(name: 'david', password: 'mUc3m00RsqyRe') user.save user.authenticate('notright') # => false user.authenticate('mUc3m00RsqyRe') # => user

password=

password=(unencrypted_password) Instance Public methods Encrypts the password into the password_digest attribute, only if the new password is not blank. class User < ActiveRecord::Base has_secure_password validations: false end user = User.new user.password = nil user.password_digest # => nil user.password = 'mUc3m00RsqyRe' user.password_digest # => "$2a$10$4LEA7r4YmNHtvlAvHhsYAeZmk/xeUVtMTYqwIvYY76EW5GUqDiP4."

password_confirmation=

password_confirmation=(unencrypted_password) Instance Public methods

serializable_hash

serializable_hash(options = nil) Instance Public methods Returns a serialized hash of your object. class Person include ActiveModel::Serialization attr_accessor :name, :age def attributes {'name' => nil, 'age' => nil} end def capitalized_name name.capitalize end end person = Person.new person.name = 'bob' person.age = 22 person.serializable_hash # => {"name"=>"bob", "age"=>22} person.serializable_hash(only: :name) # => {"n

as_json

as_json(options = nil) Instance Public methods Returns a hash representing the model. Some configuration can be passed through options. The option include_root_in_json controls the top-level behavior of as_json. If true, as_json will emit a single root node named after the object's type. The default value for include_root_in_json option is false. user = User.find(1) user.as_json # => { "id" => 1, "name" => "Konata Izumi", "age" => 16, # "created_at" => "2006/08/0