-1

im sure this is a simple enough error i just cant figure it out. I'm installing ryanto/acts_as_votable gem and i'm getting the following issue. There are issues similar but I cant find any fixes that can be implemented before the rake db:migrate

Gemfile:

gem 'acts_as_votable', '~> 0.10.0'

then I'm

rails generate acts_as_votable:migration
rake db:migrate

Then the rake is being aborted and i'm getting this message

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

The new error :

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]
LiffeyD
  • 103
  • 6
  • 1
    Please add your routes file here. – Bharat soni Jul 03 '17 at 12:53
  • 1
    It sounds that your gem would like your ruby version to be upgraded to 2.3.1 : `RubyDep: WARNING: Your Ruby is outdated/buggy. RubyDep: WARNING: Your Ruby is: 2.3.0 (buggy). Recommendation: upgrade to 2.3.1.` – Jaeger Jul 03 '17 at 12:55
  • 1
    Read the error message carefully, so you ll gate your answer. – Ganesh Sagare Jul 03 '17 at 12:56
  • Hey, thanks a mill.my routes file is added above, i #out the code for the gem as its not migrated yet. The last time the gem as updated was 3 years ago so I assume the new ruby wouldn't make a difference, am I wrong in that? – LiffeyD Jul 03 '17 at 12:57
  • 1
    have you run `bundle install` ? – puneet18 Jul 03 '17 at 12:59
  • yes I have ran bundle install – LiffeyD Jul 03 '17 at 13:01
  • 1
    @LiffeyD correct your routes file. Its outside the block. Check my posted answer – puneet18 Jul 03 '17 at 13:06
  • 1
    Correct, I have already noticed the error in the log that's why to tell you to add the file here. And finally, you got answered. – Bharat soni Jul 03 '17 at 13:38
  • 1
    Now you just have to go through all act_as_votable migration files and add the version they were generated at ([4.2]) For example: `class AddMissingIndexes < ActiveRecord::Migration[4.2]` There is an issue and a pull request open to fix this, but in the meantime you have to add it yourself. https://github.com/ryanto/acts_as_votable/issues/142 – epergo Jul 03 '17 at 15:05
  • @epergo That worked Thanks a million, you are a gent. – LiffeyD Jul 03 '17 at 17:18

4 Answers4

1

Your routes file is incorrect.

Correct code:

Rails.application.routes.draw do
  devise_for :users
  root to: "posts#index"
  resources :posts
end
puneet18
  • 4,341
  • 2
  • 21
  • 27
  • Thanks a million i'm now getting an error saying i need to state the version it was written for but I can access it because it wont migrate it. I will writhe the message in the codebox above – LiffeyD Jul 03 '17 at 13:06
1

I think the problem is with your routes file,You have added resources :posts outside of Rails.application.routes.draw block.

MyAppName::Application.routes.draw do
   #resources
end
Vivek
  • 859
  • 7
  • 11
1

NoMethodError: undefined method `resources' for main:Object

You have resources :posts outside of the block. Put that inside

Rails.application.routes.draw do
  devise_for :users
  root to: "posts#index"
  resources :posts
end
Pavan
  • 33,316
  • 7
  • 50
  • 76
0

Fix I had to go to db>migrate>'file i was migrating' and add

class AddMissingIndexes < ActiveRecord::Migration[4.2]
LiffeyD
  • 103
  • 6