找不到合适的路线(路线)

时间:2015-12-30 20:13:56

标签: ruby-on-rails ruby routes config dbmigrate

您好我尝试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 然后我收到错误消息,有没有人看到任何问题?提前致谢! 顺便说一下,这是第10章ruby on rails教程。

4 个答案:

答案 0 :(得分:1)

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

root路线也缺少它的选项。

答案 1 :(得分:0)

您的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

答案 2 :(得分:0)

可能只是删除这两行将解决它:

get 'account_activations/ edit'

get 'account_activation/ edit'

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

答案 3 :(得分:0)

我认为您可能正在使用

resources :account_activations

错误...应该在模型上使用资源,在这种情况下,它是一个控制器 - &gt;这是你的日志抱怨的。 以下是您的一些参考:http://guides.rubyonrails.org/routing.html#resources-on-the-web

  

资源路由允许您快速声明给定资源控制器的所有常用路由。而不是为索引,显示,新建,编辑,创建,更新和销毁操作声明单独的路由,而是一条资源丰富的路由在一行代码中声明它们。

也许跑一个

rake routes

查看您有哪些路线,以及“资源:account_activations”是否正在制作修改路线。