When I call Factory.attributes_for(:some_class)
I obviously get back a hash of attributes for that class.
{ :attribute_one => "hello", :attribute_two => "goodbye" }
Is there a convenient way to retrieve this attributes hash with string keys rather than symbols?
{ "attribute_one" => "hello", "attribute_two" => "goodbye" }
xdazz's answer is a good option but if you want to actually convert the keys to strings instead of accessing the hash indifferently you can use stringify_keys
Factory.attributes_for(:some_class).stringify_keys
This will let you access the value by both symbol and string key.
Factory.attributes_for(:some_class).with_indifferent_access
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With