2017-07-03 117 views
-1

確定這是一個足夠簡單的錯誤,我只是無法弄清楚。 我正在安裝ryanto/acts_as_votable gem,並且出現以下問題。 有類似的問題,但我不能找到可以耙分貝之前執行任何修復:遷移rake db:遷移gem時遷移被中止

的Gemfile:

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) 

Routes.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] 
+1

請將您的路線在這裏提交。 –

+1

這聽起來像是你的寶石想把你的ruby版本升級到2.3.1:'RubyDep:警告:你的Ruby已經過時了/ buggy。 RubyDep:警告:您的Ruby是:2.3.0(越野車)。建議:升級到 2.3.1.' – Jaeger

+1

請仔細閱讀錯誤消息,以便您能答覆。 –

回答

1

你的路線文件不正確。

正確的代碼:

Rails.application.routes.draw do 
    devise_for :users 
    root to: "posts#index" 
    resources :posts 
end 
+0

感謝一百萬我現在得到一個錯誤,說我需要說明它的編寫版本,但我可以訪問它,因爲它不會遷移它。我會在 – LiffeyD

1

我認爲這個問題是你的路由文件,您已經添加resources :postsRails.application.routes.draw塊。

MyAppName::Application.routes.draw do 
    #resources 
end 
+0

以上的代碼框中轉發消息嗨,我修改了我的路由文件,上面的代碼,謝謝。 – LiffeyD

+0

這是我的c9.io的鏈接,如果它有助於https://ide.c9.io/davemc/project-paperclip – LiffeyD

1

NoMethodError: undefined method `resources' for main:Object

你有resources :postsblock的。把裏面

Rails.application.routes.draw do 
    devise_for :users 
    root to: "posts#index" 
    resources :posts 
end 
0

修復我不得不去分貝>遷移>「文件我是遷移」,添加

class AddMissingIndexes < ActiveRecord::Migration[4.2]