1
我在認證中使用Rails 4在Action本書中遇到了一個問題。Rails 4 rake db:在設計安裝後遷移導致無效路由錯誤
我將gem "devise", "~> 3.4.1"
添加到我的Gemfile中,運行bundle
,並運行生成器rails g devise:install
。
然後,我發現用戶喜歡它是用書寫的:rails g devise user
。
直到這部分一切都很好。然後我跑bundle exec rake db:migrate
和得到這個錯誤:
$ bundle exec rake db:migrate
rake aborted!
ArgumentError: Invalid route name, already in use: 'new_user_session'
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:360:in `block in devise_session'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:359:in `devise_session'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:249:in `block (4 levels) in devise_for'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:249:in `each'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:249:in `block (3 levels) in devise_for'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:452:in `with_devise_exclusive_scope'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:248:in `block (2 levels) in devise_for'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:351:in `block in devise_scope'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:350:in `devise_scope'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:247:in `block in devise_for'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `each'
/var/lib/gems/2.3.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `devise_for'
/home/rafal/ruby_workspace/ticketee/config/routes.rb:4:in `block (2 levels) in <top (required)>'
/home/rafal/ruby_workspace/ticketee/config/routes.rb:3:in `block in <top (required)>'
/home/rafal/ruby_workspace/ticketee/config/routes.rb:1:in `<top (required)>'
/home/rafal/ruby_workspace/ticketee/config/environment.rb:5:in `<top (required)>'/var/lib/gems/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
這裏是我的routes.rb
:
Rails.application.routes.draw do
devise_for :users
Rails.application.routes.draw do
devise_for :users
root "projects#index"
resources :projects do
resources :tickets
end
end
end
請發佈'config/routes.rb'的內容。 – SoAwesomeMan
我把它作爲回答 – fafal
Okomikeruko的解決方案看起來合法。如果有效,您應該考慮接受它作爲答案:http://meta.stackexchange.com/a/5235/249307。另外,請不要發佈數據作爲答案 - 要麼1)**編輯**您的問題包括它;或者2)在https://gist.github.com等其他地方發佈它,並使用** edit **在您的問題中包含鏈接。 – SoAwesomeMan