迁移gem

时间:2017-07-03 12:52:03

标签: ruby-on-rails ruby acts-as-votable

我确定这是一个简单的错误,我只是无法弄明白。 我正在安装ryanto / acts_as_votable gem并且我遇到了以下问题。 有类似的问题,但我找不到任何可以在rake db:migrate

之前实现的修复

的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

#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 个答案:

答案 0 :(得分:1)

您的路线文件不正确。

正确的代码:

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

答案 1 :(得分:1)

我认为问题在于您的路线文件,您已在resources :posts阻止之外添加了Rails.application.routes.draw

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

答案 2 :(得分:1)

  

NoMethodError:main:Object

的未定义方法`resources'

resources :posts之外的block。把它放在里面

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

答案 3 :(得分:0)

修复我必须转到db&gt; migrate&gt;'文件我正在迁移'并添加

if(isset($_POST['action']) && $_POST['action'] == "SaveImages"){
    foreach($_POST['images'] as $product){
        $ProductID = $product['ProductID'];
        $Image = $product['Image'];
        $ImagePath = $product['ImagePath'];
        // your code
    }
}