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'
看起来是因为我正在添加通配符(*)。知道如何解决这个问题吗?
答案 0 :(得分:6)
通配符组件也需要有一个“标签”,例如
match "/myroute*something" => redirect("http://google.com"), :as => :myroute
将分别匹配/myrouteblah
和/myroute/hello/world
,其中params[:something]
分别为blah
和/hello/world
。
编辑:如果您还没有,请查看http://guides.rubyonrails.org/v3.2/routing.html#route-globbing。
答案 1 :(得分:0)
试试这个:
match ':redirect' => redirect("http://google.com"), :as => :myroute , :constraints => { :redirect => /myroute.?/i }