Rake cannot find gems in vendor/gems - ruby-on-rails

I'm trying to publish a Rails 3.1 (upgraded from 3.0) application. After submitting the code I ran
bundle install --path vendor/gems RAILS_ENV=production
It worked. I've got a directory vendor/gems/ruby/1.9.1, in which bin, cache, doc, gems and specifications are located. However, when I run a rake task I've got an error:
$ rake db:migrate RAILS_ENV=production
Could not find authlogic-3.0.3 in any of the sources
Run `bundle install` to install missing gems.
It's not a problem with authlogic, it's both in gems and specifications directories, and it was annotate mentioned in the error before I removed it from the gemfile.
What can be wrong?
I'm using Ubuntu 10.10, Ruby 1.9.2p0, Rails 3.1 and Rake 0.9.2. The code was deployed by capistrano, vendor directory is placed in shared folder and linked in the releases.

If you want to use the project's gems then you should use bundle exec command e.g.,
bundle exec rake db:create
also require authlogic gem in gem file.
gem 'authlogic'
First delete the whole gems directory from vendor/ folder. You should use this:
bundle install --path=vendor/gems
no needs for specifying the environment.

Related

How to install Webpacker with Rails

I'm trying to install Webpacker to be able to launch a Yarn server. I'm on Rails 5 and the gem is installed.
When I run
bundle exec rails webpacker:install
I get:
>> rails aborted!
Don't know how to build task 'webpacker:install' (see --tasks)
bin/rails:15:in `require'
bin/rails:15:in `<main>'
(See full trace by running task with --trace)
The command doesn't seem to exist.
install the rails/webpacker gem as from the documentation I am quoting
Installation
You can either add Webpacker during setup of a new Rails 5.1+ application using new --webpack option:
Available Rails 5.1+
rails new myapp --webpack
Or add it to your Gemfile:
Gemfile
gem 'webpacker', '~> 3.0'
OR if you prefer to use master
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
and finally, run following to install Webpacker:
bundle
bundle exec rails webpacker:install
OR (on rails version < 5.0)
bundle exec rake webpacker:install
First, add the following to the gemfile:
gem "webpacker", "~> 3"
Then, bundle install:
bundle exec rails webpacker:install
I was trying to install webpacker and, for me, the solution was a bit different from those listed here.
I was trying gem install webpacker, but it doesn't change the Gemfile.
Then I searched for why it doesn't change, and to make it work I had to use:
bundle add webpacker
After that I used:
rails webpacker:install
Are you sure webpacker is installed correctly?
Maybe there is an issue with your use of bundle exec try running without it. You can also try running with the --tasks flag to verify if the webpacker tasks are available to use.

"rails s" doesn't work but "bundle exec rails s" works. Why?

I copied the app from Github. Installed a proper version of Ruby using rbenv. I installed bundler by gem install bundler and ran bundle install --path vendor/bundle. All gems were installed in vendor/bundle directory in the app. Now I wonder, why rails s command doesn't work but bundle exec rails s works? The same with rspec command. Is this because I installed gems in vendor/bundle directory? I'm confused.
Also, when I run gem list I get only a few gems, but there are a lot of them in vendor/bundle directory.
Please tell me why gem list command doesn't see gems from vendor/bundle directory and why I need to run commands with bundle exec. Thank you!
The purpose of having the bundle exec command is to look/search for the command which you want to run inside the current bundle or installed gems inside your vendor directory.
If you are running newer rails (v5) then have a look at the binstubs which copies over the command executeable in the bin directory. So that you can simply call
bin/rails server
This is the same approach which is followed by the deployment solutions which we currently have. They create a .bundle directory which eliminates the need to do bundle install everytime.
Prefixing bundle exec to commands executes the command as it isn't of rails. To fix it we can simply run:
gem install rails
This will install all dependencies of rails and commands like rails s or rails c will work without bundle exec.

Your bundle is locked to rake (12.0.0), but that version could not be found in any of the sources listed in your Gemfile.

I get the following error message when starting the rails server:
Your bundle is locked to rake (12.0.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (12.0.0) has removed it. You'll need to update your bundle to a different version of rake (12.0.0) that hasn't been removed in order to install.
I specified gem 'rake', '12.0.0' in the gemfile but that doesn't fix it. I tried bundle update rake, deleting the Gemfile.lock and generating it with bundle exec bundle install. I also prepended `bundle exec1 to al my commands which does nothing.
My Gemfile.lock already specifies rake version 12.0.0, and there are no other versions installed.
See my gemfile:
http://pastebin.com/L4tVFWz9
And rakefile:
http://pastebin.com/K7p2ajsE
I tried the solutions suggested in Already activated rake version different than what Gemfile requires prevents rake commands
Different methods to solve this issue,
Step1:
gem install rubygems-bundler
gem regenerate_binstubs
Step2:
Remove the vendor/bundle directory.
Run bundle install to rebuild it
Step3:
Try, gem update bundler
Here is a link where the issue got solved. Check this is very useful
Try:
gem install rubygems-bundler
gem regenerate_binstubs
Not really a fundamental solution, but if you really have to run some Rails commands urgently and needs a temporary fix, try bundle exec rails c rather than bin/rails c.
Enter command :-
bundle update rake

How does Bundle know what gems to install?

How does Bundle know what gems need to be installed when I do a "bundle install"? Does it look for gems in a specific directory?
Bundler looks for a your gem dependencies in the Gemfile at the root of your Rails project folder, and executes the command bundle install.

Ruby on Rails : Rake db:create -> Could not find gem

I begin with ruby on rails and I'm trying to create my first blog. So i ran:
rails new blog -database=mysql
There was an error:
Gem::InstallError: The 'json' native gem requires installed build tools.
But since i saw a json directory in my blog's directory i didn't care.
So i run the command to create the database:
rake db:create --trace
And i had another error:
Could not find gem 'rails (= 3.1.3) x86-mingw32' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
Does anybody knows what is the problem?
Also may need to run
bundle exec rake db:create
you can try "gem list | grep json" to check if json is already install.
Then, you can add following line in Gemfile (in your site's directory):
gem 'json'
and then
bundle install json or bundle update json
Good luck,

Resources