In working out a fix for the flip_keys_and_values bug in
map.resources, I got to thinking that the current API for specifying
extra actions is backwards. The code doesn't use the un-flipped hash
at all, and the flipped version is actually more compact to specify.
For example:
map.resources :articles, :member => { :reply => :get,
:create_reply => :post, :spawn
=> :post, :split => :post }
- or -
map.resources :articles, :member => { :get => :reply,
:post =>
[:create_reply, :spawn, :split] }
The second form seems simpler to me, and it's what the code needs
internally already so no fancy flipping required. It also has the
advantage that you could create routes that support multiple http
methods, if that doesn't break something else:
map.resources :articles, :member => { :get => [:reply],
:post =>
[:reply, :spawn, :split] }
That gets us back to being able to do post-back actions, which is a
nice pattern and I think makes controllers simpler. Don't know what
it would do to the routing internals for using http methods though.
--josh
On Jul 31, 2006, at 1:27 PM, Josh Susser wrote:
Since trac is still out to lunch...
It's great to see SimplyRestful at last being rolled into trunk.
The code refactoring looks nice, however there is a bug in handling
extra actions in the collection/member/new options.
flip_keys_and_values(hash) will lose all but one of the actions
that have the same method.
flip_keys_and_values({ :reply => :get, :create_reply
=> :post, :spawn => :post, :split => :post })
# => { :get => :reply, :post => :create_reply }
(YMMV for the particular :post action retained depending on the
randomish hash ordering.)
I don't think you'll be able to get flip_keys_and_values to do what
you want and return a hash. The old way of inverting a hash into
an array of arrays seemed to work fine.
--
Josh Susser
http://blog.hasmanythrough.com
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core