Translate Columns updated
Small update regarding translate columns which I thought I’d mention. The latest version available on github now finally has some proper testing and much improved handling of model validations.
Some of the code has been re-factored and now uses the unusual alias_method_chain method to override the standard saving process in a Rails-standard way. A quick example:
def save_with_translation(perform_validation = true)
if perform_validation && valid? || !perform_validation
# Do something
save_without_translation(false)
else
false
end
end
translate_columns includes something similar to the method above for saving translations, in order for it to be used before a normal save, we need to add it to the save method chain:
alias_method_chain :save, :translation
This will automatically create an alias to the old save method as save_without_translation and alias save to save_with_translation. Which is nice. Took me a while to discover this, eventually I found it on the Ruby on Rails forum which discusses how save_without_validation does its magic.
No comments yet