Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-2glob

Rails 2 vs Rails 3: Why are route globs no longer split?


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?


Solution

  • 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?)