没有找到正确的路线(路线)

Does not find the right Route(routes)

您好,我在尝试执行 bundle exec rake db:migrate 时遇到了问题 我从来没有遇到过这个问题,这是代码

bundle exec rake db:migraterake aborted!
ArgumentError: Missing :controller key on routes definition, please check your routes.
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:275:in `check_part'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:255:in `check_controller_and_action'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:178:in `normalize_options!'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:100:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:78:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:78:in `build'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:1559:in `add_route'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:1536:in `decomposed_match'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:1517:in `block in match'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:1507:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:1507:in `match'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:689:in `map_method'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:650:in `get'
/home/ubuntu/workspace/sample_app/config/routes.rb:3:in `block in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
/usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/route_set.rb:410:in `draw'
/home/ubuntu/workspace/sample_app/config/routes.rb:1:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:40:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/file_update_checker.rb:75:in `call'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/file_update_checker.rb:75:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:27:in `updater'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/initializable.rb:30:in `run'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application.rb:352:in `initialize!'
/home/ubuntu/workspace/sample_app/config/environment.rb:5:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application.rb:328:in `require'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application.rb:328:in `require_environment!'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/application.rb:457:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

这是我做的第一部分rails generate controller AccountActivations \ edit --no-test-framework

然后routes.rb

Rails.application.routes.draw do

  get 'account_activations/ edit'

  get 'account_activation/ edit'

  get 'sessions/new'

  root                 'static_pages#home'
  get 'help'        => 'static_pages#help'
  get 'about'       => 'static_pages#about'
  get 'contact'     => 'static_pages#contact'
  get 'signup'      => 'users#new'
  get 'login'       => 'sessions#new'
  post 'login'      => 'sessions#create'
  delete 'logout'   => 'sessions#destroy'
  resources :users
  resources :account_activations, only: [:edit] 
end

然后我 运行 这个代码:

$ rails generate migration add_activation_to_users \
> activation_digest:string activated:boolean activated_at:datetime

我修改这个新文件

class AddActivationToUsers < ActiveRecord::Migration
  def change
    add_column :users, :activation_digest, :string
    add_column :users, :activated, :boolean, default: false
    add_column :users, :activated_at, :datetime
end end

最后 bundle exec rake db:migrate 然后我收到错误消息,有人看到任何问题吗?提前致谢! 顺便说一句,这是 rails 教程的第 10 章 ruby。

helpabout 路由缺少它的控制器(可选操作)参数。

root 路线也缺少选项。

你的routes.rb错了。

Rails.application.routes.draw do

  get 'account_activations/edit'

  get 'account_activation/edit'

  get 'sessions/new'

  root :to => 'static_pages#home'

  get 'help'        => 'static_pages#help'
  get 'about'       => 'static_pages#about'
  get 'contact'     => 'static_pages#contact'
  get 'signup'      => 'users#new'
  get 'login'       => 'sessions#new'
  post 'login'      => 'sessions#create'
  delete 'logout'   => 'sessions#destroy'
  resources :users
  resources :account_activations, only: [:edit] 

end

可能只需删除这两行即可解决问题:

get 'account_activations/ edit'

get 'account_activation/ edit'

您已在此处和资源中两次定义此路由。

我想你可能正在使用

resources :account_activations

错误...应该在模型上使用资源,在本例中它是一个控制器 -> 这就是您的日志所抱怨的。 这是您的一些参考资料:http://guides.rubyonrails.org/routing.html#resources-on-the-web

Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index, show, new, edit, create, update and destroy actions, a resourceful route declares them in a single line of code.

也许运行一个

rake routes

查看您有哪些路线可用,如果 "resources :account_activations" 甚至正在编辑路线。