Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messages #4

Open
micapam opened this issue Feb 20, 2013 · 6 comments
Open

Error messages #4

micapam opened this issue Feb 20, 2013 · 6 comments

Comments

@micapam
Copy link

micapam commented Feb 20, 2013

This library is great, especially since you fixed the memory leak! So thanks for all your hard work. Just have one problem and I'm not sure how to work out where it's going wrong...

For my usual validations I can configure error messages via locales e.g. in my config/locales/en.yml I have:

  activerecord:
    errors:
      messages:
        blank:      is missing

Now the problem is, while for any attributes with normal validations I get the error message I want ('foo is missing'), for any attributes that I validate in a validation_scopes block, I get the standard error message ('bar can't be empty') - ignoring my locale file.

I looked in the source and I couldn't see why this would be. Any ideas?

@gtd
Copy link
Owner

gtd commented Mar 2, 2013

I'm not familiar enough with the latest i18n to hazard a guess and I'm a bit swamped at the moment to launch a full-scale investigation. If I had the error in my app I would change my validation-scopes and rails gems to local clones of the git repos and start printlining the areas of the code responsible for pulling these error codes. If you have a public repo with an app that demonstrates the problem (or simply a failing test case!) I could probably hone in on the problem fairly quickly, without that it's a bit too much setup for me to undertake right now.

@kriskhaira
Copy link

Hi Gabe :) Stumbled upon this while trying to figure out the same thing in Rails 4.2.1 with your gem; so I thought I'd leave a comment for others since this issue is open anyway.

I ended up just using ActiveRecord translations for ActiveModel:

  activerecord:
    errors: &model_errors
      models:
        product:
          attributes:
            base:
              name_of_warning: "your warning string here"
  ...
  activemodel:
    errors: *model_errors

@samstickland
Copy link

Hi,

Just starting trying to use this gem and I've ran into this problem straight away too. Can you explain the meaning of:

errors: &model_errors

and:

errors: *model_errors

In your yml file above?

I've tried:

en:
  activerecord:
    attributes:
      company:
        number: "Company Registration Number"

Which translates the attribute number in a normal validation but doesn't work with this gem.

@samstickland
Copy link

Aha, I see. The default error validation looks up:

en.activerecord.attributes.company.reg_address

But this gem looks up:

en.activemodel.attributes.company.reg_address

(which I found by using the excellent https://github.com/fphilipe/i18n-debug)

I still don't understand the meanings of the &model_errors and *model_errors

@kriskhaira
Copy link

@samstickland &model_errors and *model_errors are just YAML anchors and aliases. You can read about them here:
http://stackoverflow.com/a/13927529
http://www.yaml.org/spec/1.2/spec.html#id2760395

@samstickland
Copy link

Thanks!

2015-08-21 8:31 GMT+01:00 Kris Khaira [email protected]:

@samstickland https://github.com/samstickland &model_errors and
*model_errors are just YAML anchors and aliases. You can read about them
here:
http://stackoverflow.com/a/13927529
http://www.yaml.org/spec/1.2/spec.html#id2760395


Reply to this email directly or view it on GitHub
#4 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants