First Rails Project: Rake Problem - ruby-on-rails

I'm running rails on Mac OS X. I think I installed it correctly, but I'm getting the following error.
$ rake db:create
(in /Users/user_name/myapp)
rake aborted!
Could not find RubyGem mocha (>= 0)
(See full trace by running task with --trace)
What is the problem? How do I fix it?

Looks like you're missing the mocha gem. Running sudo gem install mocha should fix the problem.

You can also use:
sudo rake gems:install
So it will go through your environment.rb to see which gems are depended upon and install them.

Related

Multiple Rails vers on same machine + rake

I've been running a Rails 3.2 with Ruby 1.9.3 for a while now. Recently I added Rails 5.1 and Ruby 2.4.
I used rvm to install Ruby2.4.
Today I had occasion to cd into one of my old projects and run rake db:migrate, and I got the following message:
Gem::LoadError: You have already activated rake 12.0.0, but your Gemfile requires rake 0.9.2.2. Prepending `bundle exec` to your command may solve this.
Prepending 'bundle exec' did solve the problem but for my knowledge I would like to understand what happened. I thought the whole point of a Gem file within the project was to lock in the required gems.
So somewhere on my machine clearly there is still rake 0.9.2.2 but why did my command 'rake db:migrate' not use that automatically?
Reason: Some of the gem might have locked rake gem to that version.You are getting this as version of rake inside gemlock file is different than the one you have already installed.
Solution1:
bundle update
Solution2:
edit the gemlock file. open Gemfile.lock and change
rake (0.9.2.2) to rake (12.0.0)
Solution3:
remove Gemfile.lock and run bundle install once again.This will create
Gemfile.lock once again.

"Missing these required gems" on specific server, gems are installed

Trying to run rake db:migrate I get:
$ rake db:migrate
(in /home/user/domains/staging)
log level debug
Missing these required gems:
haml ~> 3.1.4
htmlentities
fastercsv
You're running:
ruby 1.8.7.72 at /usr/bin/ruby1.8
rubygems 1.3.7 at /home/user/.gem/ruby/1.8, /usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
rake aborted!
no such file to load -- json
I have two servers en both are updated via a git repository. On one server everything works fine, on the other I get the above error.
Whats up?
Have you tried bundle install or sudo bundle install in production? You might also try bundle exec rake db:migrate instead of just rake db:migrate. These are kind of guesses, but might help.
Is the path to the "ruby"/"rake" etc executables pointing at the correct one on the server that isn't working? It looks like you want to use REE, but your stack trace is 1.8, not REE.
You may need to export an environment variable to update your path to point at the correct Ruby binaries.

Rake error Rake::DSL

When I try doing rake db:migrate I get this error
rake aborted! uninitialized constant Rake::DSL
/home/laptop/RubymineProjects/website2/Rakefile:10
What do I have to do to fix this? I tried with multiple different rake versions. I'm running Rails 3.0.9, Ruby 1.8.7 and Ubuntu 11.04.
Include this in your Rakefile
require 'rake/dsl_definition'
Then bundle install and you're (hopefully) good to go :)
If this didn't work, try the following:
You're probably using Rake 0.87 so gem install rake -v=0.9.2 is something you should do.
Then remove old rake with gem uninstall rake -v=0.9.1
Then bundle update
And if you still have any problem then...
Add the following to your Rake file
module ::YourApplicationName
class Application
include Rake::DSL
end
end
Comment below if you are having any problem after all this little hacks...
on Debian Squeeze this is what I do to fix that:
Configure squeeze-backports and upgrade rubygems
apt-get install -t squeeze-backports rubygems
remove rake and it's executable
gem uninstall rake
rm /usr/bin/rake
install rake again, now the executable file will be /usr/local/bin/rake and error is gone
gem install rake

Rake gems:install says "could not find table", rake db:migrate says "required gems missing"

I just cloned a github repo on a fresh Ubuntu machine, running sqlite3 for all environments. rake db:create says development.sqlite3 already exists. rake db:migrate says I'm missing a bunch of required gems and should run rake gems:install. rake gems:install, of course, says it Could not find table 'studies', which sounds to me like something rake db:migrate should fix.
I looked around the net and while lots of people have gotten 'could not find table' errors, they all got them from rake db:migrate, not rake gems:install. I'm suspecting it's an application-specific error, but still, any ideas would be appreciated.
PS: Ruby 1.8.7, Rails 2.3.8.
You can always install separate gems with gem install -r <gem name> or gem install -v=<gem version> -r <gem name> command, not using rake.
Is this a Rails 3 app? If so, you should run:
bundle install
Rails 3 uses Bundler instead of the rake tasks to manage gems. http://gembundler.com/
Did you try running with the trace option? Might help pin down the failing gem:
rake -t gems:install

Rake Gems Install Error

I am getting the following error when trying to install gems:
Mohammad-Azams-MacBook-Pro:awesomecats azamsharp$ sudo rake gems:install
Password:
(in /Projects/awesomecats)
rake aborted!
Don't know how to build task 'gems:install'
(See full trace by running task with --trace)
Mohammad-Azams-MacBook-Pro:awesomecats azamsharp$
If the task isn't listed in the output of rake -T then it isn't defined and you can't run it.
Rails 3 removed this task in favor of using Gemfile and bundler as the official gem installation procedure as gems:install was often tricky to get working properly.

Resources