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

Undefined method `locale' for model using update_attributes #15

Closed
phlegx opened this issue Nov 11, 2014 · 2 comments
Closed

Undefined method `locale' for model using update_attributes #15

phlegx opened this issue Nov 11, 2014 · 2 comments

Comments

@phlegx
Copy link

phlegx commented Nov 11, 2014

Hi!

Rails: 4.1.7
Globalize: 4.0.2
Globalize Accessors: 0.1.5

The following code:

# /app/models/category.rb
...
translates :name
globalize_accessors
validates :name, presence: true, uniqueness: { scope: :locale }
# /db/seeds/../...rb

I18n.locale = :en
category = Category.find_or_initialize_by(name: name[:en])
category.update_attributes({
    name_de: name[:de],
    name_fr: name[:fr]
})

Produces this error:

NoMethodError: undefined method `locale' for #<Category:0x0000000885e398>

Works in console by doing:

2.1.4 :017 > c = Category.find_or_initialize_by(name: 'Test En')
2.1.4 :017 > c.name_de = 'Test De'
2.1.4 :017 > c.name_de
 => 'Test De'

Is the problem in the uniqueness validation of attribute name?

@phlegx
Copy link
Author

phlegx commented Nov 12, 2014

Solved, because gem globalize 4.0.2 has a uniqueness validation for this purpose. But another question is open: Validation errors associated on translated attributes including locale globalize/globalize#386

Any idea?

@phlegx phlegx closed this as completed Nov 12, 2014
@phlegx
Copy link
Author

phlegx commented Nov 12, 2014

SOLVED - Validation errors associated on translated attributes including locale globalize/globalize#386

Added possible solution, here: globalize/globalize#386 (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

1 participant