Comments (9)
Any thoughts on this, now that Rails 5 is released?
from delocalize.
I have managed to get it for rails 5 working by doing this:
https://github.com/clemens/delocalize/compare/master...zilverline:d264d6fd1f627e47fef317cdeea78ca5d273cf88?expand=1
It's backward compatible, but it ain't pretty.
from delocalize.
Still, not bad!
Mine isn't pretty either:
def delocalize_hash(hash, options, base_key_stack = [])
hash.each do |key, value|
key_stack = [*base_key_stack, key] # don't modify original key stack!
hash[key] = if value.is_a?(Hash) or
(defined?(ActionController::Parameters) and value.is_a?(ActionController::Parameters))
delocalize_hash(value, options, key_stack)
elsif value.is_a?(Array)
key_stack += [:[]] # pseudo-key to denote arrays
value.map { |item| delocalize_parse(options, key_stack, item) }
else
delocalize_parse(options, key_stack, value)
end
end
end
from delocalize.
I'll have to have a closer look. I'll schedule some time tomorrow for it.
from delocalize.
If you want, check out the rails5 branch and let me know if this works for you. each_pair
is implemented for Hash
as well as ActionController::Parameters
so this should be fine. It's also implemented for a small number of other classes (e.g. Struct
) but since the method in question is private and not intended to be given anything but Rails params
, I'm kind of OK with that.
from delocalize.
Nice. But doesn't delocalize_parser_for
need the same fix, too?
from delocalize.
I had failing tests for Rails 5 before the fixes but now everything's green (except for JRuby – I'll investigate that). So either this isn't a problem or the tests aren't covering a scenario that has issues.
If I read the code right, here's what happens in Rails 5's ActionController::Parameters
: The params hash gets injected into the Parameters
object and stored in an instance variable as a ActiveSupport::HashWithIndifferentAccess
(https://github.com/rails/rails/blob/5-0-0/actionpack/lib/action_controller/metal/strong_parameters.rb#L142). This means that while the shell doesn't subclass Hash
anymore, the core still does. So when I'm calling delocalize_hash
with the outer shell, it receives an instance of ActionController::Parameters
(which is not a Hash
) but then iterates on its attributes (which still are a Hash
or Array
or whatever but not a ActionController::Parameters
instance).
Long story short: To me it looks like we don't need to adapt delocalize_parser_for
as well since it's always called with the individual elements of ActionController::Parameters
which are never an instance of that class (unless something goes very wrong or someone tries to do some wonky stuff).
If anyone's still having trouble with it, I'm happy to accept a failing test case and fix it accordingly.
from delocalize.
Ah, thank you for sorting this out.
I also gave rails5
a test drive and works.
from delocalize.
I've released 1.1.0 with Rails 5 support. Thanks for the initial fix and helping with discussion and testing!
from delocalize.
Related Issues (20)
- Delocalize in Production HOT 2
- Delocalize does not work with Gem best_in_place HOT 3
- dirty attributes are not correctly set HOT 7
- License missing from gemspec HOT 2
- rails g fails - 0.3.1 HOT 1
- not working in rails/ruby 2 HOT 7
- thousand problem HOT 2
- Error delocalizing params with nested attributes HOT 3
- Parsing a localized date HOT 3
- Rails 4.2 compatibility HOT 13
- French Date issue. Probably Regexp fail? HOT 7
- Setting an invalid value in a time field while doing update_attributes! sets the value to nil HOT 3
- Rails 3.2.22.2 app fails to start: uninitialized constant Delocalize::DelocalizableParameters HOT 10
- Number parser failing with i18n fallbacks HOT 1
- Demo application not available HOT 5
- Are the rails_ext files needed?
- Regular expression for date time format does not escape regexp sensitive characters
- New controller-side paradigm not working for me HOT 10
- Regexp does not support many strptime formats HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delocalize.