This project is archived and is in readonly mode.
Rails slice() helper incompatibility in Rails 2.1.1
Reported by Nate Wiger | September 23rd, 2008 @ 12:04 AM | in 2.x
String.slice used to return the same types of keys as the original hash. As of Rails 2.1.1, however, it always returns stringified keys.
You can see this behavior in a snipped like the following:
user_params = params.slice(:username, :password)
In Rails 2.1.0 and earlier, you could then say:
user_params[:username] user_params[:password]
However, in Rails 2.1.1, you can only get to them stringified:
user_params['username'] user_params['password']
Attempting to use the symbols yields nil values.
Comments and changes to this ticket
-
Michael Johann September 23rd, 2008 @ 09:36 AM
I'm not able to find the issue. Everything works fine with this testcase:
def test_slice_access_with_symbols
original = { :username => 'motu', :password => 'motupass', :email => 'myemail@email.domain'} original.slice!(:username, :password) username = original[:username] assert_equal username, "motu"
end
-
Adam Cigánek September 23rd, 2008 @ 09:53 AM
I guess the problem is that
params
isHashWithIndifferentAccess
butslice
gives back just plainHash
. Perhapsslice
should give return of the same type as it's receiver? -
Michael Johann September 23rd, 2008 @ 10:10 AM
Using the method @@@ ruby with_indifferent_access@@@ on the Hash converts the hash into an object of type @@@ruby HashWithIndifferentAccess@@@. So the following test case should fail, of there is an issue, I guess. I'm still not able to reproduce the problem. Maybe I on the wrong way.
def test_indifferent_slice_access_with_symbols original = { :username => 'motu', :password => 'motupass', :email => 'myemail@email.domain'}.with_indifferent_access original.slice!(:username, :password).with_indifferent_access username = original[:username] assert_equal username, "motu" end
-
Michael Johann September 23rd, 2008 @ 11:09 AM
Now I understand the problem. Thank you for cleaning my eyes. ;-)
Let's see...
-
Michael Johann September 23rd, 2008 @ 11:53 AM
- Tag changed from 2.1, bug, core_ext, helper to 2.1, bug, core_ext, helper, patch
Great. Works. :-)
-
Repository September 23rd, 2008 @ 01:08 PM
- State changed from new to committed
(from [3b9c2fdf9e1813b8317d529aeb4074806e14ade2]) slice now returns indifferent hash if called on one
Signed-off-by: Michael Koziarski michael@koziarski.com
[#1096 state:committed]
Conflicts:
activesupport/lib/active_support/core_ext/hash/slice.rb
-
Repository September 23rd, 2008 @ 01:08 PM
(from [2e75bd0808f4dcac328b690aaad176cbfe96773e]) slice now returns indifferent hash if called on one
Signed-off-by: Michael Koziarski michael@koziarski.com
[#1096 state:committed] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1096 Rails slice() helper incompatibility in Rails 2.1.1 [#1096 state:committed]
- 1096 Rails slice() helper incompatibility in Rails 2.1.1 [#1096 state:committed] http://github.com/rails/rails/co...