Skip to content


Subversion checkout URL

You can clone with
Download ZIP


redirect in router with block is not working with "do...end" blocks #8160

gravis opened this Issue · 5 comments

2 participants


The code in the documentation (

match 'jokes/:number', :to => redirect do |params, request|
  path = (params[:number].to_i.even? ? "/wheres-the-beef" : "/i-love-lamp")

will raise a redirection argument not supported (ArgumentError) exception with rails 3.2.8 and ruby 1.9.3-p286 (not tested with other versions yet).

The exception looks like (when trying to start to app):

/var/www/myapp/staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/redirection.rb:120:in `redirect': redirection argument not supported (ArgumentError)
        from /var/www/myapp/staging/releases/20121109152239/config/routes.rb:12:in `block (2 levels) in <top (required)>'
        from /var/www/myapp/staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/mapper.rb:624:in `scope'
        from /var/www/myapp/staging/releases/20121109152239/config/routes.rb:3:in `block in <top (required)>'            from /var/www/myapp/staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
        from /var/www/myapp/staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'            from /var/www/myapp/staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:260:in `draw'            from /var/www/myapp/staging/releases/20121109152239/config/routes.rb:1:in `<top (required)>'

Changing the code to something like:

match 'jokes/:number', :to => redirect { |params, request|
  path = (params[:number].to_i.even? ? "/wheres-the-beef" : "/i-love-lamp")

solved the issue.


Sorry, this is how Ruby works. do..end will be passed as argument to match in this case, not redirect, whereas the {} version will be passed to redirect instead.

If you need to use do..end, you will need to wrap match with parentheses, kinda like this:

match('jokes/:number', :to => redirect do |params, request|
  path = (params[:number].to_i.even? ? "/wheres-the-beef" : "/i-love-lamp")



@carlosantoniodasilva what about a doc update then?


Well, yeah, sounds good :). It's fixed in master already, but not in 3-2-stable as you saw. Thanks.


Awesome :+1:
Thanks a lot ;)


Done :)

@nikitug nikitug referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.