redirect("http://google.com"), :as => :myroute The line above in r...">

Error using wildcards and redirecting to routes in Rails

match "/myroute*" => redirect("http://google.com"), :as => :myroute 

The line above in routes.rb causes the following error

 /Users/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/racc/parser.rb:349:in `on_error': (Racc::ParseError) parse error on value ")" (RPAREN) from /Users/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/racc/parser.rb:99:in `_racc_do_parse_c' from /Users/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/racc/parser.rb:99:in `do_parse' 

This seems to be because I'm adding a wildcard (*). Any idea how to solve this?

+3
source share
2 answers

Wildcard components must also have a label, for example

 match "/myroute*something" => redirect("http://google.com"), :as => :myroute 

will match /myrouteblah and /myroute/hello/world , where params[:something] are blah and /hello/world respectively.

EDIT: http://guides.rubyonrails.org/v3.2/routing.html#route-globbing , if you have not already done so.

+6
source

Try the following:

 match ':redirect' => redirect("http://google.com"), :as => :myroute , :constraints => { :redirect => /myroute.?/i } 
0
source

All Articles