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

上面的行routes.rb导致以下错误

/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'

看起来是因为我添加了通配符 (*)。知道如何解决这个问题吗?

4

2 回答 2

6

通配符组件也需要有一个“标签”,例如

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

将分别匹配/myrouteblah/myroute/hello/worldwhere params[:something]isblah/hello/world

编辑:如果您还没有,请查看http://guides.rubyonrails.org/v3.2/routing.html#route-globbing 。

于 2012-10-17T02:45:39.283 回答
0

试试这个:

match ':redirect' => redirect("http://google.com"), :as => :myroute , :constraints => { :redirect => /myroute.?/i }
于 2012-10-17T02:42:06.293 回答