This project is archived and is in readonly mode.

#4431 ✓resolved
David Chelimsky

inconsistent support in assigns API

Reported by David Chelimsky | April 17th, 2010 @ 08:55 PM

On http://github.com/rails/rails/blob/master/actionpack/lib/action_con..., the docs say you can access assigns with assigns(:key).

It turns out that you can actually access assigns in any of these three ways:

assigns(:key)
assigns("key")
assigns["key"]

But you can not access assigns with assigns[:key]. Actually, you can use assigns[:key], but it always returns nil, leading to false results in tests with no indication that you're doing something wrong.

My thought is that if you can use strings or symbols with assigns(...), you should probably be able to use strings or symbols with assigns[...]. The alternative would be to prevent access with keys (or warn in that case), but that seems like overkill to me.

Here's a patch to handle the more flexible case:

http://github.com/dchelimsky/rails/commit/9531c36bbc681b5b905f695b8...

Comments and changes to this ticket

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

Referenced by

Pages