Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a plugin in rails 3, getting a Commands is not a module (TypeError)

I'm trying to install this as a plugin:

https://github.com/phatworx/rack_ip_restrictor

So I run:

$ rails plugin install git://github.com/phatworx/rack_ip_restrictor.git

This errors with:

/Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/railties-3.0.5/lib/rails/commands/plugin.rb:277:in `<top (required)>': Commands is not a module (TypeError)
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
    from /Users/userme/.rvm/gems/ruby-1.9.2-p180@andyw/gems/railties-3.0.5/lib/rails/commands.rb:17:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Suggestions, ideas? Thanks

like image 536
AnApprentice Avatar asked Oct 25 '22 02:10

AnApprentice


2 Answers

There's a solution out on GitHub - check the comments.

like image 139
acconrad Avatar answered Oct 27 '22 10:10

acconrad


@acconrad is correct. the concrete solution is ( If you use rails 3.0.9- with rake 0.9.2, you should add include Rake::DSL to Rakefile just after require 'rake'. Then add module Commands; end to script/rails just before require 'rails/commands', you will not get 'Commands is not a module (TypeError)' error message any more.) :

1.in Rakefile,

require File.expand_path('../config/application', __FILE__)
require 'rake'
# add this line of code
include Rake::DSL 

2.in script/rails:

APP_PATH = File.expand_path('../../config/application',  __FILE__)
require File.expand_path('../../config/boot',  __FILE__)
# add this line of code
module Commands; end
require 'rails/commands'

3.then run this command:

$ bundle exec rails plugin install git://github.com/sbecker/asset_packager.git

the plugin will be installed.

like image 39
Siwei Avatar answered Oct 27 '22 11:10

Siwei