-
Notifications
You must be signed in to change notification settings - Fork 85
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
Doesn't work with ActiveRecord::AttributeMethods::Serialization #144
Comments
Yeah, I know Globalize does this, but I seem to remember the implementation is kind of nasty and breaks with AR releases. I'm not really eager to support this unless it's simple and clean. |
Can you explain exactly what you're doing with serialization? Do you want to translate a serialized attribute? |
Yes, I'm adding i18n to an existing project and stumbled upon this # Rails 4.2.10
class SomeModel < ActiveRecord::Base
serialize :aliases
end So, a text column serialized to Array with I'm really time strapped here so right now I'm running with this ugly hack, replacing class SomeModel < ActiveRecord::Base
def self.aliases_coder
@coder ||= ActiveRecord::Coders::YAMLColumn.new Array
end
def aliases=(array)
aliases_backend.write(Mobility.locale, self.class.aliases_coder.dump(array))
array
end
def aliases(options = {})
options[:locale] ||= Mobility.locale
self.class.aliases_coder.load(aliases_backend.read(options.delete(:locale), options)) || []
end
end Seem to work for now. |
Sorry, to clarify: you're not translating |
Oh I see, you want to translate serialized arrays... My position is that if the problem is relevant, and it can be solved in a backend-independent way without hacking into AR internals, it might be a good idea. In this case it seems like it might be possible. |
Yes, correct. The reason I haven't submitted a pull request is because I'm not sure what Mobility internals to use. |
I am also stuck with this problem after trying to move away from Globalize, @shioyama do you have any thoughts on how this problem could be solved? |
Sorry I haven't had time to look at this. I will say that I am very wary of adding special code to handle ActiveRecord features, since this is what makes Globalize so fragile and complicated. I'd prefer to keep things simple and focus on core features, which is why I haven't looked at this. If it involves stuff that may break with a Rails upgrade, I'll be pretty wary about introducing it since I don't want to have to deal with upgrading patches. (e.g. the dirty plugin always causes problems when Rails is upgraded. I'm keeping it since it's very popular.) I can help someone implement this if you want to take a go at it. The basic steps would be:
|
no need to apologise @shioyama It looks like Globalize inspects the serialized attribute and does a type check for |
Closing this, not something Mobility will implement. Happy to provide advice to anyone wanting to implement it as a plugin. |
When using
ActiveRecord::AttributeMethods::Serialization
, columns doesn't get serialized properly.The text was updated successfully, but these errors were encountered: