How are you doing? <!-- app/views/home/index.html.erb —> <h1><%= t :home_title %></h1> <p><%= t :home_body %></p> <time datetime="<%= @published_at.iso8601 %>"> <%= l @published_at %> </time>
Hello world home_body: How are you doing? errors: messages: blank: "must be provided" irb(main):003:0> album.errors.full_messages => [“Name must be provided”]
Hello world home_body: How are you doing? errors: attributes: name: # applies to any attributes called “name” blank: "must be provided” irb(main):003:0> album.errors.full_messages => [“Name must be provided”]
Hello world home_body: How are you doing? activerecord: errors: models: album: # the model’s name category: # the attribute’s name blank: "must be selected" irb(main):003:0> album.errors.full_messages => ["Category must be selected”]
errors: # The default format to use in full error messages. format: "%{attribute} %{message}" irb(main):003:0> album.errors.full_messages => ["Category must be selected"]
["Number of tracks must be greater than 0"] class Album < ApplicationRecord validates :number_of_tracks, comparison: { greater_than: 0 } end # lib/active_model/locale/en.yml en: errors: # The default format to use in full error messages. format: "%{attribute} %{message}"
["Number of tracks must be greater than 0"] class Album < ApplicationRecord validates :number_of_tracks, comparison: { greater_than: 0 } end # config/locales/en.yml en: errors: # Overriden format. format: "%{message}"
ApplicationRecord validates :number_of_tracks, comparison: { greater_than: 0 } end irb(main):003:0> album.errors.full_messages => ["You must upload at least one track"] # config/locales/en.yml en: errors: # Overriden format. format: "%{message}" activerecord: errors: models: album: number_of_tracks: greater_than: "You must upload at least one track”
ApplicationRecord validates :name, presence: true end # config/locales/en.yml en: errors: # Overriden format. format: "%{message}" activerecord: errors: models: album: name: blank: "Enter a name for your album" irb(main):003:0> album.errors.full_messages => ["Enter a name for the album"]
:account_must_pass_modulus_check private def account_must_pass_modulus_check return if modulus_check.valid? errors.add(:account_number, "The account number you entered is not valid") end end
:account_must_pass_modulus_check private def account_must_pass_modulus_check return if modulus_check.valid? errors.add(:account_number, "The account number you entered is not valid") end end
:account_must_pass_modulus_check private def account_must_pass_modulus_check return if modulus_check.valid? errors.add(:account_number, :failed_modulus) end end # app/config/locales/en.yml activerecord: errors: models: direct_debit_mandate: account_number: failed_modulus: "The account number you entered is not valid"
one: There is one item in stock. other: There are %{count} items stock. <!-- app/views/products/_product.html.erb —> <h1><%= product.name %></h1> <p><%= t 'product_availability', count: product.stock.count %></p> <%= link_to t(:product_buy_now), buy_product_url(product) %>