0

In Rails 2, if I had the following route:

get 'show/:user_id(/*tags)' => 'show#tags', :as => 'show_tags'

I would expect this back from show/123/foo/bar:

params[ :tags ] # [ 'foo', 'bar' ]

Now, in Rails 3, it returns:

params[ :tags ] # 'foo/bar'

Any idea why they changed this?

Jason
  • 3,379
  • 25
  • 32

1 Answers1

1

The router in rails was completely rewritten for Rails 3.0. It's outlined pretty well in The Rails Guide on the subject. I would just consider it one of the many BC breaking changes of a transition between major versions.

The fix is very straightforward - just a small change to your action.

tags = params[:tags].split(/\//).reject(&:empty?)
deefour
  • 34,974
  • 7
  • 97
  • 90
  • Thank you. Shame that I technically have to doubly specify globs in both the router and the action. Not very DRY, but thanks so much for the insight! – Jason Aug 31 '13 at 01:14
  • Any easy way to override how Rails currently does it to make it behave like before by default? – Jason Aug 31 '13 at 01:15
  • @JasonTFeatheringham not that I know of; I'm not an expert on the router internals though. – deefour Aug 31 '13 at 03:59