【发布时间】:2011-11-15 09:20:31
【问题描述】:
当我在控制器中使用 redirect_to 'index' 时,我收到以下错误。 -关于 Ruby 1.8.7 和 Rails 3.1.1-
Started GET "/presentations/1" for 127.0.0.1 at Tue Nov 15 01:48:42 +0200 2011
Processing by PresentationsController#show as HTML
Parameters: {"id"=>"1"}
Redirected to http://localhost:3000index
Completed 302 Found in 2ms
[2011-11-15 01:48:42] ERROR URI::InvalidURIError: the scheme http does not accept registry part: localhost:3000index (or bad hostname?)
这就是它在 routes.rb 中的样子
..
get 'about_us' => 'presentations#index', :as => 'about_us'
..
resources :presentations
显然它试图重定向到http://localhost:3000index 而不是http://localhost:3000/presentations/index,但我不明白为什么。如果我使用redirect_to presentations_path 或redirect_to :controller => 'presentations', :action => 'index',一切正常,但为什么会这样?我认为如果 redirect_to 使用现有设置引用同一个控制器,我应该能够使用 redirect_to 而不定义任何控制器参数,还是我错了?
【问题讨论】:
标签: ruby-on-rails