RVM why don't gems install to locally to project folder? - ruby-on-rails

So here's my problem:
I have a project and I am trying to install Gems locally to that project. For example if I install devise from the Gemfile and then run a bundle install it won't put any of the controllers in the controllers directory of the project. Instead I have to hunt through the RVM directories to get that particular gem's controllers, copy them to my project and then start writing my project from there.
Any suggestions?

I think the comment above answered your question - when you add a gem like Devise to your app, it doesn't generally drop code directly into your application. Sometimes it provides a generator which will install some parts of it, but mostly it alters config files so that the code in the gem gets pulled into your app when it starts.
You can ask bundler to install gems in the "vendor" subdirectory of your app, instead of in the main RVM/Ruby location, with the --path option. But you usually only want to do that for production deployment, not development.

Related

Bring Rails gem locally

I am working on a Rails 4 application and one of the requirements is to have all of the Gems that normally go into the Gemfile brought in locally to the machine for use. This includes Rails and after looking at many google search results I am not able to find anyone talking about using the Rails gem locally on a Rails project.
My train of thought here is to clone the rails project from Github locally and then using the bundler config path to target that directory for rails, but I am not sure how well will that solution work or even if it will work.
I will appreciate any input here or if anyone has experience with this situation I will appreciate any insight.
The bundle install does that ?
If you want to install any gem to your project go to the project root on cmd
$ gem install gemname
Doing that you locally installed the gem afterwards you want to make sure its loaded to your project so you can run
$ bundle install
And simply like that your gem is installed. Hope that helps
If you have your project on github, then you can clone it using command.
git clone github-repository-url
And then from that project directory, run command
bundle install --path vendor
It will install all your rubygems into vendor directory.

Does 'bundle install' install all the required gems on my computer permanently?

I am new to rails and am learning about bundler. I understand that bundle install installs all the gems specified in the gemfile but where does it install them to?
Does it install them on my computer permanently so that they can be used by any future project?
If so doesnt this mean my computer gets filled with random gem versions and gem installs that I needed for one example project but may never use again?
By default, bundle install is going to install at the root level so all users on a computer could have access to the gems. So 'yes' it is permanent (at least not tied to your application, you can remove them whenever you want).
Take a look at the man pages for bundler. In here, you'll notice that you can specify to install to a local directory.
Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem
repository. In this case, install them to vendor/bundle.
$ bundle install --path vendor/bundle
Further bundle commands or calls to Bundler.setup or Bundler.require
will remember this location.
This will let you install the gems to a location inside your application. So when you delete the example app, you also delete the associated gems.
Also, if you would like to see where a specific gem is installed (say you want to look at its source code), type bundle show <gemname>. This will spit out the path to that gem.
The short answer is 'yes'. The longer answer is that there are some technologies which will reduce or eliminate the problems associated with this effect.
If you install 'RVM':
https://rvm.io/
this will allow you to install multiple versions of Ruby and create individual 'gemsets'. As you enter the directory that contains your project, the ruby version and gemset settings are automatically picked up and the active Ruby version will change. This way you can keep gems separate between projects - and use several Ruby versions at once, including JRuby and other esoteric versions.
To find out where gems are stored, type:
gem environment
into your command line and look for the INSTALLATION_DIRECTORY entry in the response.

Why do I need to run bundle install after I reformatted my computer?

I'm very new to ruby on rails which is why I'm trying to get a basic understanding of how it works. I have just created my very first rails app which is located in my dropbox folder. As I reformatted my computer two questions arise.
1) I had to do bundle install again in order to launch my local server. Why is that?
2) Also, prior to reformatting, I did cmd+p in sublime to search for files. However, files within gems didn't show in the results - now they do.
Everything works just as it did before I reformatted, I'm just trying to understand those two elements.
Thanks in advance!
Gem are not stored within your project.
If you are using RVM to maintain ruby version then gems are stored within that rvm folder.
As you have formatted your PC, it has removed gem folder from your system.
So, it is requesting for "bundle install".
This command will installing gems listed in applications GEMFILE.
If gem are already present in gem folder then it just use it for your project.
Gems that you require in your project are not stored in your project they are normally stored in a gems folder within your ruby install folder which would be on your local drive.
If for instance your start a new rails project you would see when you run bundle install every gem it checks for would already be installed becasue it's looking into the local gems folder.

"could not locate gemfile" when doing bundle install on existing rails project

I've been given an existing rails project that I am trying to play around with. however, when I try to run bundle install or rake db:migrate, I run into problems so essentially, i can't really do anything with the code I've been given.
The biggest problem as I see it right now is the fact that it can't locate my gemfile when I bundle install?
How can I find my gemfile.. is there supposed to be one in the root folder of the application?
Is there another step I need to take to initialize an existing project that someone has just copied and pasted to me? Thanks!
Yes, you should have a Gemfile in the root directory of your app.
If you are developing in a Rails 2 app, you might want to check out the Bundler.io page about Rails 2.3:
http://bundler.io/v1.7/rails23.html
If you are using Rails 3+ you can take a learn from Bundler's page on Rails 3 use:
http://bundler.io/v1.7/rails3.html
If you just need to get started with a Gemfile, go to a different directory and generate a dummy app:
$ rails new temporary-app
Copy over the Gemfile to your directory. It will only have the default gems listed, but you may be able to "discover" your needed gems as you go. If you happen to have a Gemfile.lock file then you can see the gems that you need at the top of the dependency tree.

How to use multiple bundle paths in Ruby on Rails (bundler)

I'm using a few gems for interactivity with my database and to provide easy pagination. After deploying my application on my server, it'll automatically execute bundle install to install those gems if they aren't installed yet. This is helpful when I deploy a codebase update including a new gem.
However, there's one gem (will_paginate) I've made a little change to (so that it always shows on what page you are, no matter the total number of pages).
Therefore, I used bundle install --local --path vendor at my local machine (OS X Lion) so that I can easily edit them (at per-app base, instead of system-wide).
Because of dependency problems, I cannot 'just' copy the vendor-folder to my web server. Therefore, I decided to add another rule to my .gitignore-file:
vendor
Because this caused my customized will_paginate-gem not to get uploaded, I executed another command:
git add -f vendor/ruby/1.8/gems/will_paginate
Now, when I push, the only gem in the vendor folder at my web server is will_paginate, which is great.
However, it doesn't get loaded, since it isn't in the bundle path.
I already tried to create a file called .bundle/config and add the following in it:
---
BUNDLE_PATH: vendor
I also tried adding BUNDLE_DISABLE_SHARED_GEMS: "0", but using this, bundle check says it's missing the shared gems.
My question is, how can I add a bundle path vendor, and fallback on the system-wide gem-path.

Resources