我使用contact_us寶石版本0.5.4Rails 4.0.x如何將contact_us gem的root動作路由到指定的動作?
我下面的代碼在我的routes.rb文件
resources :contacts, controller: 'contact_us', only: [:new, :create] do
root :to => 'contact_us#new'
end
在我的理解上面的路線
contacts
將只支持
:new
和
:create
行動
,並與指定控制器controller: 'contact_us'
還將其與根/
會重定向到#new
動作,但是當我在瀏覽器中點擊http://localhost:3000/contact-us它說
未知的動作
行動「索引」不能爲ContactUsController
發現我已經升級,從3.2.19軌道版本4.0.13和紅寶石以2.0.0p481
老代碼工作正常使用Rails 3.2.19和1.8.7紅寶石
resources :contacts,
:controller => 'contact_us',
:only => [:new, :create]
match 'contact_us' => 'contact_us#new'
如果我只用get
在上面的代碼拋出這個錯誤更改match
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:430:in `add_route「:無效路由名稱,已在使用中:「CONTACT_US」 (引發ArgumentError)
你可能已經使用
:as
選項定義的兩條路線具有相同名稱 ,否則你可能會改寫已經 由資源具有相同定義的路由命名。對於後者,可以 限制與resources
創建的路線如下解釋:
是的,我做到了,但它拋出了另一個錯誤,請檢查問題更新 –
這是如此奇怪。我開始了一個新的小測試項目。它工作順利... – Albin
是你的整個路線文件? – Albin