-1

我确定这是一个足够简单的错误,我只是想不通。我正在安装 ryanto/acts_as_votable gem,我遇到了以下问题。有类似的问题,但我找不到任何可以在 rake db:migrate 之前实现的修复

宝石文件:

gem 'acts_as_votable', '~> 0.10.0'

那我是

rails generate acts_as_votable:migration
rake db:migrate

然后耙子被中止,我收到了这条消息

davemc:~/workspace/newsroom (rating) $ rake db:migrate
RubyDep: WARNING: Your Ruby is outdated/buggy.
RubyDep: WARNING: Your Ruby is: 2.3.0 (buggy). Recommendation: upgrade to 
2.3.1.
RubyDep: WARNING: (To disable warnings, 
see:http://github.com/e2/ruby_dep/wiki/Disabling-warnings )
rake aborted!
NoMethodError: undefined method `resources' for main:Object
/home/ubuntu/workspace/newsroom/config/routes.rb:5:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:286:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:286:in `block in load'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:258:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:286:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:55:in `block in load_paths'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:55:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:55:in `load_paths'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:18:in `reload!'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:41:in `block in updater'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/file_update_checker.rb:81:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:42:in `updater'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/routes_reloader.rb:31:in `execute_if_updated'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application/finisher.rb:128:in `block in <module:Finisher>'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/initializable.rb:30:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/initializable.rb:59:in `block in run_initializers'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/initializable.rb:58:in `run_initializers'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application.rb:353:in `initialize!'
/home/ubuntu/workspace/newsroom/config/environment.rb:5:in `<top 
(required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:292:in `require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:292:in `block in require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:258:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-
5.1.1/lib/active_support/dependencies.rb:292:in `require'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application.rb:329:in `require_environment!'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-
5.1.1/lib/rails/application.rb:445:in `block in run_tasks_blocks'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top 
(required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

路由.rb

 Rails.application.routes.draw do
   devise_for :users
     root to: "posts#index"
 end
  resources :posts #do
     #member do
    #  put "like" => "posts#upvote"
   #   put "dislike" => "posts#downvote"

 #end

#结尾

新错误:

StandardError: An error has occurred, this and all later migrations  
anceled:

Directly inheriting from ActiveRecord::Migration is not supported. Please 
specify the Rails release the migration was written for:

  class ActsAsVotableMigration < ActiveRecord::Migration[4.2]
4

4 回答 4

1

您的路线文件不正确。

正确代码:

Rails.application.routes.draw do
  devise_for :users
  root to: "posts#index"
  resources :posts
end
于 2017-07-03T13:01:22.403 回答
1

我认为问题出在您的路线文件上,您已在块resources :posts之外添加。Rails.application.routes.draw

MyAppName::Application.routes.draw do
   #resources
end
于 2017-07-03T13:01:27.133 回答
1

NoMethodError:main:Object 的未定义方法“资源”

你有resources :posts外面的block。把那个放在里面

Rails.application.routes.draw do
  devise_for :users
  root to: "posts#index"
  resources :posts
end
于 2017-07-03T13:01:36.497 回答
0

修复我必须去 db>migrate>'file i was migrate' 并添加

class AddMissingIndexes < ActiveRecord::Migration[4.2]
于 2017-07-03T17:20:59.827 回答