kdweber89
kdweber89

Reputation: 2174

Editing simpleform locales to enable custom error messages

I have a form within my app that I build using simple_form. What I am trying to do is edit my error messages to something a little different than the default. I am working on my simple_form.en.yml file and I think that may be where my problems are happening.

With what I have, i'm not sure I understand what exactly goes in the settings file, and I am hoping someone can go over what I have and advise me on where to go.

My model is like so (this is my entire model)

class FormSubmission < ActiveRecord::Base
  after_create :email_sales

  validates :first_name, :last_name, :organization, :email, :phone, :recognition, :inquiry, presence: true

  private

  def email_sales
    FormSubmissionMailer.update_sales(self).deliver_now
  end
end

Here is one of the areas of my view

= simple_form_for @form_submission do |f|

  .fieldSet.span8
    .field.reco
      = f.input :first_name, input_html: { class: "formStyling" }, label: "First name", required: false

Finally, in my simple_form.en.yml file I have this here

en:
  activerecord:
    errors:
      models:
        formsubmission:
          attributes:
            email:
              blank: "cannot be empty"

Upvotes: 0

Views: 1519

Answers (1)

Matouš Bor&#225;k
Matouš Bor&#225;k

Reputation: 15944

Simple_form does nothing special for validation error messages I18n and leaves all work to the default Rails I18n processing. The simple_form.en.yml localization file only deals with the various options to display the form and its elements (labels, hints, etc., see the docs) and has nothing to do with error messages.

So, if you need to set the error messages localization, have a look at the official Rails guide on I18n instead. Actually, I think that your simple_form.en.yml example might work, if you moved the error message localizations to the default Rails locale file for English: config/locales/en.yml.

Upvotes: 2

Related Questions