Question

I'm following Railstcast #188 to get declarative authorization running on my Rails 3 app (using Ruby 1.9.2) and am running into an issue getting the gem to install.

Ryan suggests adding it in config/environment.rb with the following:

config.gem "declarative_authorization", :source => "http://gemcutter.org"

Then install it with sudo rake gems:install.

However when I try that I get an error:

/Users/Travis/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:314:in `bin_path': can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)

I tried rake gems:install, but got this error:

Don't know how to build task 'gems:install'

The instructions to install declarative_authorization at GitHub recommend a different process, which I also followed but still couldn't get past rake:gems install.

Does anyone know what may be happening so I can get around this?

UPDATE: Here's what my config/environment.rb looks like:

RVM -v: rvm 1.10.0-pre Gem list:

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.9, 3.0.5)
actionpack (3.0.9, 3.0.5)
activemodel (3.0.9, 3.0.5)
activerecord (3.0.9, 3.0.5)
activeresource (3.0.9, 3.0.5)
activesupport (3.0.9, 3.0.5)
addressable (2.2.6)
arel (2.0.10)
aws-s3 (0.6.2)
aws-sdk (1.3.2)
builder (2.1.2)
bundler (1.0.21 ruby)
cocaine (0.2.1, 0.2.0)
erubis (2.6.6)
faraday (0.7.6, 0.7.5)
fastercsv (1.5.4)
gemcutter (0.7.1)
heroku (2.14.0)
httparty (0.8.1)
i18n (0.6.0, 0.5.0)
jquery-rails (1.0.19, 1.0.16)
json (1.6.5)
launchy (2.0.5)
mail (2.2.19)
metaclass (0.0.1)
mime-types (1.17.2)
mocha (0.10.3, 0.10.2, 0.10.0)
multi_json (1.0.4)
multi_xml (0.4.1)
multipart-post (1.1.4)
nifty-generators (0.4.6)
nokogiri (1.5.0)
paperclip (2.5.2, 2.5.0, 2.4.5)
pg (0.12.2, 0.12.0, 0.11.0)
polyamorous (0.5.0)
polyglot (0.3.3)
rack (1.2.5, 1.2.4)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.9, 3.0.5)
railties (3.0.9, 3.0.5)
rake (0.9.2.2, 0.9.2, 0.8.7)
rake-compiler (0.7.9)
ransack (0.6.0, 0.5.8)
rdoc (3.8)
rest-client (1.6.7)
rubyzip (0.9.5)
simple_oauth (0.1.5)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
term-ansicolor (1.0.7)
thor (0.14.6)
treetop (1.4.10)
twitter (2.1.0, 2.0.2)
tzinfo (0.3.31, 0.3.30)
uuidtools (2.1.2)
xml-simple (1.1.1)
Was it helpful?

Solution

Not sure how your environment is set up, but simply installing rake should do it. If you provide more detail (rvm, bundler, etc.) it may be of help.

gem install rake

Upon further inspection of your path, I see you're using RVM. If your paths are installed properly, you can either use the RVM Global gemset, execute the line above.

Another suggestion I have is checking out the CanCan railscast as that is the bigger norm for authorization these days, more supporters as well.

http://railscasts.com/episodes/192-authorization-with-cancan

"A few episodes ago we covered Declarative Authorization. While it is an excellent authorization plugin for Rails it can be a little heavy for simpler sites. After writing the Railscast on Declarative Authorization Ryan Bates looked for an alternative solution and, failing to find one that suited his needs, decided to write his own, CanCan." - RBates

After seeing your environment, let's try to separate the environments a little. Do this.

rvm gemset create some_other_name
rvm gemset use some_other_name
bundle install

See if this isolates your environment enough.

EDIT: I don't use rake gems:install anymore. You have bundler installed, and I'm assuming you want to use it. I do use rails g gemname:install when the documentation for such exists, I'm going to look at the railscasts again and see what rbates is telling you.

On the CANCAN github page, it says: In Rails 3, add this to your Gemfile and run the bundle command. gem "cancan".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top