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

The line above in routes.rb is causing 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'

Looks like it is because I'm adding a wildcard (*). Any idea how to solve this?

Martin
  • 11,216
  • 23
  • 83
  • 140

2 Answers2

6

Wildcard components need to have a "label" as well, e.g.

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

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

EDIT: Check out http://guides.rubyonrails.org/v3.2/routing.html#route-globbing if you haven't already.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
tristanm
  • 3,337
  • 2
  • 27
  • 40
0

Try this:

match ':redirect' => redirect("http://google.com"), :as => :myroute , :constraints => { :redirect => /myroute.?/i }
Brad Werth
  • 17,411
  • 10
  • 63
  • 88