-
Notifications
You must be signed in to change notification settings - Fork 34
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
Exception when localize a model with polymorphic belongs to #18
Comments
I forgot, we are workarounding this issue using that bizarre code: class Person < ActiveRecord::Base
belongs_to :personable, :polymorphic => true
accepts_nested_attributes_for :personable
def personable_attributes=(personable_attributes, options = {})
self.personable ||= personable_type.constantize.new
personable.localized.assign_attributes(personable_attributes, options)
end
end This version is more ugly than first option, do not work for all cases and assume we want localized version all the time but it's working for now ;) |
With this, we fix carlosantoniodasilva#18.
I don't have an idea off the top of my head, but I'll try to search and think what can be done. Meanwhile if you want to send a failing test case, would help :). Thanks! |
Any news on this one? |
Not actually, I haven't stopped to put much thought on it :) I may have some time available to get back to it in a couple weeks, in the meanwhile any help would appreciated. Thanks! |
Hey mate,
Seems like we have a "integration" problem with active record and i18n alchemy but I'm not sure.
Just to you follow my production code, we can't accept nested attributes for polymorphic associations:
It's ok, not the best solution but you can work around it:
And, it just works now:
But, if we try to use localized version:
The alchemy offending code is that:
This won't work because polymorphic associations do not have the class defined.
I'm not sure about using
build_#{association_name}
because we will mutate the object, but maybe that is expected if we are receiving the#{association_name}_attributes
in a localized proxy.Anyway, I need this polymorphic association to be assigned localized.
Thoughts? :-)
The text was updated successfully, but these errors were encountered: