can not use cancan - ruby-on-rails-3

I am following rails casts episode 192 for cancan (http://railscasts.com/episodes/192-authorization-with-cancan?autoplay=true).
I have ruby 1.9.3
and rails 3.2.3
My gem file has this content
group :test, :development do
gem 'rspec-rails', '~> 2.5'
end
group :test do
gem 'cucumber-rails', '1.0.6'# use this instead of the one in the book
gem 'capybara'
gem 'database_cleaner'
end
gem 'dynamic_form'
gem 'factory_girl'
gem 'devise', '~>1.4.3'
gem 'email_spec'
gem 'cancan'
and in the environment.rb file I have added
config.gem 'cancan'
when I run bundle command I see this...
Using warden (1.0.6)
Using devise (1.4.9)
Using dynamic_form (1.1.4)
Using rspec-core (2.11.0)
Using rspec-expectations (2.11.1)
Using rspec-mocks (2.11.0)
Using rspec (2.11.0)
Now my question is: when I run:
sudo rake gems:install
then why do I see this:
Could not find warden-1.0.6 in any of the sources
Run `bundle install` to install missing gems.
and also in my gem.lock file why does it show...
devise (1.4.9)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)

That railscast is from Dec 14, 2009 back when Rails 2 was the standard.
You should go through the instructions at https://github.com/ryanb/cancan which focus more on Rails 3 and Bundler.
bundle install will install your Gemfile contents into your current RVM gemset, in this case, probably the default gemset. Do NOT use sudo to install gems. To list the gems installed in the gemset, just run gem list. Run bundle list to show all of the gems in the current application bundle.

Related

Bundle Update could not find dependencies while upgrading Rails app from 4.0 to 5.0

I am trying to upgrade my existing Rails 4.2 application to Rails 5.0. Have changed the Rails gem to 5.0.2 in Gemfile as below.
source "https://rubygems.org"
gem "rake", "~> 0.9.2"
#gem "rails", "~> 4.2.7.1"
gem 'rails', "~> 5.0.1"
gem "mysql2"
gem "mime-types", "~> 1.16", require: "mime/types"
gem "rubyzip", "~> 1.1.0"
gem "nokogiri", "1.6.8".
gem "apn_on_rails", "0.4.1", git:"https://bitbucket.orgsheridangroupapn_on_rails.git"
gem "gdata_19", "~>1.1.5"
gem "gcm_on_rails", "0.2.1", git: "https://bitbucket.org/sheridangroup/gcm_on_rails"
gem "open4", "1.0.1"
gem "rmagick", "2.13.2", require: "RMagick"
gem 'aws-sdk-v1' #aws-sdk v1 is used for url signing, as v2 has a one-week expiration limit
gem 'aws-sdk', '~> 2'
gem "libxml-ruby", "~> 2.7.0", require: "libxml"
gem "bitly", "0.10.0"
gem "uuid", "~> 2.3.7"
gem "htmlentities", "4.3.4"
gem "paper_trail", "~> 6.0.2"
gem "mechanize"
gem "rbtree", "0.4.2"
gem "resque"
gem "yajl-ruby" # For resque
gem "json", "~> 1.8.3"
gem "minitest"
gem "will_paginate"
gem "configatron", "~> 2.13.0"
gem "american_date", "~> 1.1.0"
gem "builder"
gem "coderay"
gem "json-schema"
gem "rspec"
gem "jquery-rails", "~> 4.2.2"
gem "jquery-ui-rails"
gem 'jquery-timepicker-addon-rails'
gem 'bcrypt', '~> 3.1.7'
gem "net-ftp-list"
gem 'recursive-open-struct'
gem 'slim'
gem 'paranoia'
gem 'typhoeus'
gem 'bundler', '1.12.5'
gem "paperclip", "~> 4.3.7"
group :test do
#gem 'spork-rails'
gem 'capybara'
gem 'poltergeist'
gem 'simplecov', require: false
gem 'simplecov-rcov', require: false
gem 'timecop'
gem 'test-unit'
end
# Used for NewRelic monitoring in Staging env only
group :staging, :production do
gem "newrelic_rpm"
gem "ey_config"
end
group :test, :development do
gem "rspec-rails", require: false
gem "listen", ">= 0.5.1", require: false
gem "machinist", "~> 2.0", require: false
gem "database_cleaner", "~> 0.9.1", require: false
gem 'pry-byebug'
end
group :development do
# <browser-debugging-tools>
gem "better_errors"
gem "binding_of_caller"
gem "meta_request"
# </browser-debugging-tools>
gem 'quiet_assets' # prevent assets pipeline logging
gem 'rubocop', '0.35.0'
end
group :assets do
gem "sass-rails"
gem "coffee-rails"
gem "uglifier", "2.7.2"
end
Tried running bundle update , but got the following error in the console.
Bundler could not find compatible versions for gem "rack":
In Gemfile:
rails (~> 5.0.1) was resolved to 5.0.1, which depends on
actioncable (= 5.0.1) was resolved to 5.0.1, which depends on
actionpack (= 5.0.1) was resolved to 5.0.1, which depends on
rack (~> 2.0)
better_errors was resolved to 2.1.1, which depends on
rack (>= 0.9.0)
capybara was resolved to 2.12.1, which depends on
rack (>= 1.0.0)
rails (~> 5.0.1) was resolved to 5.0.1, which depends on
actioncable (= 5.0.1) was resolved to 5.0.1, which depends on
actionpack (= 5.0.1) was resolved to 5.0.1, which depends on
rack-test (~> 0.6.3) was resolved to 0.6.3, which depends on
rack (>= 1.0)
resque was resolved to 1.27.2, which depends on
sinatra (>= 0.9.2) was resolved to 1.1.0, which depends on
rack (~> 1.1)
sass-rails was resolved to 5.0.6, which depends on
sprockets (< 4.0, >= 2.8) was resolved to 3.7.1, which depends on
rack (< 3, > 1)
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 5.0.1)
quiet_assets was resolved to 1.0.0, which depends on
rails (~> 3.1)
Bundler could not find compatible versions for gem "railties":
In Gemfile:
coffee-rails was resolved to 4.2.1, which depends on
railties (< 5.2.x, >= 4.0.0)
jquery-rails (~> 4.2.2) was resolved to 4.2.2, which depends on
railties (>= 4.2.0)
jquery-timepicker-addon-rails was resolved to 1.4.1, which depends on
railties (>= 3.1)
quiet_assets was resolved to 1.0.1, which depends on
railties (~> 3.1)
rails (~> 5.0.1) was resolved to 5.0.1, which depends on
railties (= 5.0.1)
I want to move on in upgrading to Rails 5.0. Can I get a direction to fix all the errors.
rspec-rails was resolved to 3.5.2, which depends on
railties (>= 3.0)
sass-rails was resolved to 5.0.6, which depends on
railties (< 6, >= 4.0.0)
Delete your Gemfile.lock file and try updating once again.

spree install undefined method mass_assignment_sanitizer

I took a look about this problem within the list of question but nothing helped.
This is my first question in stackoverflow so please accept my apologies in case I do something wrong. Also I still have a lot of english to improve.
I'm installing Spree following the github instructions
$ gem install spree
$ rails new my_store
$ spree install my_store
when I get this message
...
Admin Password [spree123]
gemfile spree
gemfile spree_usa_epay
gemfile spree_skrill
run bundle install from "./my_store"
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
precompiling assets
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
...
Well, as the guide suggests, in case of circular dependency issues do:
$ gem install spree_cmd
$spree install my_store -A
gemfile spree
gemfile spree_usa_epay
gemfile spree_skrill
run bundle install from "./my_store"
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
precompiling assets
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
I changed directory to the app and run the command:
$cd my_store
$bundle install
and I get the following error
Bundler could not find compatible versions for gem "rails":
In Gemfile:
spree_usa_epay (>= 0) ruby depends on
rails (<= 3.1.3, >= 3.1.1) ruby
rails (3.2.1)
after this I changed the gem file to work with rails 3.1.3 and coffeescript gems and repeat the whole process again and I get this.
Users/Snake/.rvm/gems/ruby-1.9.3-p0/gems/activerecord- 3.1.3/lib/active_record/base.rb:1088:in `method_missing': undefined method `mass_assignment_sanitizer=' for ActiveRecord::Base:Class (NoMethodError)
from /Users/Snake/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/railtie.rb:59:in `block (3 levels) in <class:Railtie>'
It think it might be something with version of rails a spree but I don't know were to start.
Does anybody had this issue before?
I running Mac OS X 10.5.8
rails 3.2.1
ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-darwin9.8.0]
ImageMagick #6.7.4-6_0+q16
As #Anatoly Ruchka suggested the problem was using rails 3.2.1, so I switched to 3.1.3.
This is what I did, I found a post of #vonconrad where he explain how to create a rail project without touch the installation.
1) I create a directory folder for my project:
$mkdir old_rails313
$cd old_rails313
$touch gemfile
$nano gemfile
2)
I pasted a gemfile definition specifying as you mention the version of rails I want, so it looks like this
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem "rspec-rails", ">= 2.8.0.rc1", :group => [:development, :test]
gem "factory_girl_rails", ">= 1.4.0", :group => :test
gem "cucumber-rails", ">= 1.2.0", :group => :test
gem "capybara", ">= 1.1.2", :group => :test
gem "database_cleaner", ">= 0.7.0", :group => :test
gem "launchy", ">= 2.0.5", :group => :test
#gem "devise", ">= 1.5.0"
gem 'spree','1.0.0'
3) then I run
bundle install
bundle exec rails new .
rails g spree:install
rails s
After installing I've got a conflict with the gem 'spree','1.0.0', so I comment it out.
Also I've got a warning but it works:
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.spree/order" is no longer supported
Thanks a lot
I think you should use rails version 3.1.3 for spree_usa_epay
TO do that you should uninstall all rails what you have on machine
to watch use
gem list -d rails
than
sudo gem uninstall rails -v ...
and create new project with
rails new my_store
than edit Gemfile and paste
gem 'spree', '1.0.0'
and
bundle install
well done
rails server

rails surveyor gem example gets sass syntax error

I'm installing the surveyor gem in a new (test) rails 3 project. I've run rails g surveyor:install, and rake db:migrate, and rake surveyor FILE=surveys/kitchen_sink_survey.rb
and then run rails server
It seems to "work" only the sass is not compiling correctly, so i get no styles and the page contains:
Syntax error: Invalid property: ":background-color= !background_color".
I'm running in Windows, with Ruby 1.9.2, the Gemfile contains
gem 'rails', '3.0.9'
gem 'sqlite3'
gem 'surveyor', :git => 'git://github.com/breakpointer/surveyor.git', :branch => 'rails3'
gem 'formtastic'
gem 'haml'
gem 'sass'
gem 'rake', '0.8.7'
Are you using the latest version of the gem? The breakpointer version is no longer the official branch. Check https://github.com/NUBIC/surveyor instead.

bundle install and rbx-require-relative

After following railstutorial.orgI am trying to run bundle install. It list use of gem like :
Using railties (3.0.7)
Using rails (3.0.7)
Using sass (3.1.3)
And this error :
Installing rbx-require-relative (0.0.5) /home/canard/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:364:in `ensure_required_ruby_version_met': rbx-require-relative requires Ruby version ~> 1.8.7. (Gem::InstallError)
from /home/canard/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:135:in `install'
...
I understand ruby 1.9.2 needs rbx-require-relative, but why it doesn't want to install it. It demand ruby ruby 1.8.7. I am little lost.
Further more after this error it stop, and my gem in my Gemfile are never read or installed...
I'm using ruby 1.9.2p180 and rails 3.0.7
Thanks for your help
rbx-require-relative is a port of Ruby 1.9’s relative_relative for Rubinus and MRI 1.8
If you're running ruby1.9 then you don't need it. Remove it from your Gemfile.
Don't require ruby-debug in your Gemfile as it has rbx-require-relative as a dependency.
Add gem 'ruby-debug19' instead
You might try to install the the ruby-debug19 gem for ruby 1.9.2.
Here is the gem info:
http://rubygems.org/gems/ruby-debug19
Here is the bundler line:
gem 'ruby-debug19'
Replacing
gem 'ruby-debug'
with
gem 'ruby-debug', :platforms => :ruby_18
gem 'ruby-debug19', :platforms => :ruby_19
in my Gemfile solved this problem for me, working on both Ruby 1.8 and 1.9.

Can't activate rack when running cucumber

I can no longer run cucumber in my rails 3 app. I'm not sure exactly when it broke but I did do some rspec work that required me to use the webrat gem and it was working before that.
My error is:
$ cucumber
Using the default profile...
can't activate rack (~> 1.2.1, runtime) for ["actionpack-3.0.7", "railties-3.0.7"], already activated rack-1.3.0 for ["rack-test-0.5.7", "cucumber-rails-0.4.1"] (Gem::LoadError)
Here is my Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'sqlite3'
gem 'devise'
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
gem 'cancan'
group :development, :test do
gem 'rspec-rails', '2.5.0'
gem 'rspec', '2.5.0'
gem 'webrat', ">= 0.7.2"
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'launchy'
gem 'factory_girl_rails'
gem 'spork'
end
Please let me know if I need to supply more info and I'll edit this.
I've tried specifying rack in my Gemfile but this doesn't seem to help and doesn't seem right. Also: If I modify my Gemfile I am running "bundle install" and then trying cucumber again. Is this the right workflow to solve this problem?
Can anyone please help?
Cheers,
Rim
Someone in my IRC channel pointed me in the right direction.
Use the context of bundler (which I don't quite understand yet)
bundle exec cucumber
This works just fine :)