# With\_indifferent\_access question Rails 2.2

**URL:** <https://www.ruby-forum.com/t/with-indifferent-access-question-rails-2-2/176852>\
**Category:** Rails\
**Created:** [October 7, 2009, 3:38am UTC](https://www.ruby-forum.com/t/with-indifferent-access-question-rails-2-2/176852 "2009-10-07T03:38:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [October 7, 2009, 3:38am UTC](https://www.ruby-forum.com/t/with-indifferent-access-question-rails-2-2/176852/1 "2009-10-07T03:38:16Z")

</div>

We had something very odd happen today after installing the twitter  
gem. We had a ton of our tests fail. When we removed the gem they  
would pass.

What it ended up being was during the building of attributes using  
nested attributes setters we were accessing the hash that was passed  
in like this:

def shade\_preference\_attributes=(shade\_preference\_attributes)  
shade\_preference\_attributes.each\_pair do |key, value|  
value.each do |shade|  
self.shade\_preferences.build(:shade\_id =\> shade  
[:shade\_id], :preference =\> shade[:preference])  
end  
end  
end

Before installing and configuring the twitter gem in our rails  
application this worked fine. After doing it, it started failing.  
The failure was because shade (a hash) did not have :shade\_id  
or :preference in it anymore. It actually always had the keys  
“shade\_id” and “preference” that never changed, but now the access of  
them by symbol started failing.

When I removed removed the config.gem line for the the twitter gem  
everything worked fine.

I’m assuming this has something to do with indifferent access. In  
both cases the shade is a normal Hash. But, in one case it appears to  
be using indifferent access and in another case not. Or could it be  
the hash was built using indifferent acces or not? I’m not exactly  
sure how that works.

The twitter gem installs a bunch of gems. Has anyone seen anything  
like this before.  
Thanks.  
Erik

---

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [October 7, 2009, 3:48am UTC](https://www.ruby-forum.com/t/with-indifferent-access-question-rails-2-2/176852/2 "2009-10-07T03:48:48Z")

</div>

It’s not the twitter gem, it’s the mash gem. The twitter gem requires  
the mash gem.  
Erik

---

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [October 7, 2009, 4:00am UTC](https://www.ruby-forum.com/t/with-indifferent-access-question-rails-2-2/176852/3 "2009-10-07T04:00:30Z")

</div>

These lines at the bottom of the mash gem are causing the issue:

# Converts all of the keys to strings

def stringify\_keys!  
keys.each{|k|  
v = delete(k)  
self[k.to\_s] = v  
v.stringify\_keys! if v.is\_a?(Hash)  
v.each{|p| p.stringify\_keys! if p.is\_a?(Hash)} if v.is\_a?(Array)  
}  
self  
end

This is defined inside class Hash…end inside of the mash  
file…hmmm…  
Erik
