rake db:seed issue - ruby-on-rails-3

I'm seeing a weird issue here when I run rake db:seed or rake db:migrate:
user#ubuntu:~/Desktop/staging/config$ bundle show activeresource
/usr/lib/ruby/gems/1.8/gems/activeresource-3.0.3
user#ubuntu:~/Desktop/staging/config$ rake db:seed
(in /home/rohan/Desktop/staging)
Could not find activesupport-3.0.3 in any of the sources
Try running `bundle install`.
user#ubuntu:~/Desktop/staging/config$ ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
I don't know what to do. Any help would be appreciated. For the record, I am using RVM.

Run bundle install. This will fix the problem.

you need to require rails in gemfile then run bundle install.
gem "rails", 'version'
now run bundle install

On the assumption that you tried running bundle install like it asked, you probably just need to use:
$ bundle exec rake db:seed
to run rake in the context of the bundle.

Related

Getting message about missing multi_json-1.3.6 when Capistrano tries to run assets:precompile

I'm using Capistrano with Rails 3.2.1. When I do cap deploy, I get this error:
Could not find multi_json-1.3.6 in any of the sources
Here's some of the relevant output leading up to this error:
* executing `deploy:assets:precompile'
* executing "cd /home/jason/dittypad-cap/releases/20120728190221 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["sniphq.com"]
[sniphq.com] executing command
** [out :: sniphq.com] Could not find multi_json-1.3.6 in any of the sources
I do have this gem, though:
$ bundle list | grep multi_json
* multi_json (1.3.6)
I was curious to see what would happen if I ran assets:precompile directly in production. The first time I tried it, it worked. But now when I try it I get this:
$ bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
/home/jason/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.22/lib/bundler/rubygems_integration.rb:143:in `block in replace_gem': rake is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /home/jason/dittypad-cap/shared/bundle/ruby/1.9.1/bin/rake:18:in `<main>'
Why is it complaining about multi_json being missing even though I have it?
I got past this by updating my bundler version to 1.0.18.
I got the answer here: Capistrano deploy/assets on Rails 3.1 fails

Can RVM hide a gem from the global gemset?

The project I'm about to work on asks for version 1.0.10 of bundler and version 0.8.7 of rake. My global gemset has slightly newer versions of these gems. I.e., the install instructions for the new project look like this:
rvm gemset use rails3
gem uninstall -x bundler
gem install bundler -v 1.0.10
gem uninstall -x rake
gem install rake -v 0.8.7 # Rake needs to be at 0.8.7
What happens is that when I'm in this new rails3 gemset I can't uninstall the existing gems (and personally I don't want to) because they exist in the global gemset.
So, question: can I somehow hide those two gems that exist in the global gemset?
I can list the gems:
$ gem list
*** LOCAL GEMS ***
addressable (2.2.6)
archive-tar-minitar (0.5.2)
awesome_print (1.0.1)
bundler (1.0.21, 1.0.10)
...
rake (0.9.2.2, 0.8.7)
...
Maybe an ancillary question would be: since I have installed the older versions into the the rails3 gemset, will rvm prefer those because the fact they were specifically installed somehow overrides the version in global, or will rvm take the gems with the highest version number?
any command except bundle should be prefixed with bundle exec and this will assure proper version of gem is used (using Gemfile)
you can avoid writing always bundle exec by using my gem rubygems-bundler
for running bundle command - rubygems will select latest available version if you do not specify one ex. bundle _1.0.10_ exec rake db:create

cron and bundle exec problem

I've upgraded to rails 3.0.9 which has introduced the rake issues. I've gotten it all resolved except for a problem with a cron job.
This used to work:
#!/bin/sh
source /usr/local/rvm/scripts/rvm
cd /home/p1r65759/apps/abbc/
/usr/local/bin/rake refresh_events RAILS_ENV=production
But now I get this error:
You have already activated rake 0.8.7, but your Gemfile requires rake 0.9.2. Consider using bundle exec.
/home/p1r65759/apps/abbc/Rakefile:4:in `'
(See full trace by running task with --trace)
How do I modify my script to use bundle exec so it will use the proper version of rake and run successfully?
Thanks.
If you are using bundler for your application then you don't need to use "/usr/local/bin/rake" as a path for rake.
you can just use bundle exec rake
so your new script will be
#!/bin/sh
source /usr/local/rvm/scripts/rvm
cd /home/p1r65759/apps/abbc/
bundle exec rake refresh_events RAILS_ENV=production
bundle exec will work because you are already in your project directory.
And don't forgot to include rake in your Gemfile.
instead of
/usr/local/bin/rake refresh_events RAILS_ENV=production
you should use
bundle exec rake refresh_events RAILS_ENV=production
or better yet install your bundle with --binstubs:
bundle install --binstubs --without development test
then you will have bin/rake:
./bin/rake refresh_events RAILS_ENV=production

thoughtbot / paperclip Gem installation

Im not going to start by saying i'm a newbie etc. Jokes, been learning Rails for nearly month using Lynda.com. I use Mac, Mac OS X Lion 10.7.
I am trying to intall Paperclip Gem but i can't seem to figure out what i'm doing wrong.
I followed the instructions on https://github.com/thoughtbot/paperclip/wiki/Installation
I added this line to my config/environment.rb
config.gem 'paperclip', :source => 'http://rubygems.org'
and i then tried to run
rake gems:install
I get an error message:
(in /Users/fred/Ruby/food)
rake aborted!
undefined local variable or method `config' for main:Object
/Users/fred/Ruby/food/Rakefile:4:in `require'
(See full trace by running task with --trace)
I then tried the following as an alternative when the above failed
script/plugin install git://github.com/thoughtbot/paperclip
I get the following error
-bash: script/plugin: No such file or directory
My question is how do install this gem? I have read a lot of other posts that say i should include gem 'paperclip', "~> 2.3" is this the same as what i did above?
Best to use bundler. Steps are
Install bundler: gem install bundler
Add to Gemfile: config.gem 'paperclip'
cd to where the Gemfile is and run: bundle install. This will install all the gems mentioned in the Gemfile
Ps. I assume that you are not using rvm. Also, you may need to prefix sudo to the command in step 1 above in case the command does not work for you due to a permission problem.

Rails 3.1 engine rake task doesnt work

I created a new engine with Rails 3.1.rc1
➜ (ruby-1.9.2-p180#rails3-pre) rails git:(master) be bin/rails plugin new ../first_engine --mountable
rails g scaffold project title:string
Scaffold is generated and now when I run
bundle exec rake db:migrate
I get the following error:
rake aborted!
Don't know how to build task 'app:db:migrate'
Tasks: TOP => db:migrate
Before rc1, it was working. But what happened now? I couldn't figure it out!
Here is the gist with all the steps and backtraces https://gist.github.com/990641
Can anyone put me the right direction?
In you Gemfile or RVM Global Gemset file. Change rake to include the version. e.g.
gem 'rake', '0.8.7'
Just using rake will not work until Rails comes out with a fix. Let us know how you get on. All the best.