Files added to my Ruby Project when using RBENV - ruby-on-rails

After installing RBEnv and rebuilding my ROR project, I now seem to have added many, many files to my project. They are in /vendor/local, and appear to duplicate what you would normally find in /Library/Ruby/Gems.
My project will not run without these files present (I get the message Could not find rake-0.9.2.2 in any of the sources.
I had difficulties with my RBEnv installation. I have what I suspect are other issues (like I have to bundle exec rails instead of just running rails). I suspect that I have done something wrong and should not have these files in my project. What I'd like to know is:
1) Should these files be there?
2) How best to fix this (if this is not how it is supposed to work)?
3) If the best approach is to start over and reinstall rbenv, how do I clear it all out?

It is true that using RBENV will end up putting copies of your gems in the project's /vendor/local folder. This is to remove any dependencies on your base gem set. These files need not be part of your source repository, as long as your 'gemfile' and your '.rbenv-version' file are included in the repository.
Another price you pay for using rbenv is that you must bundle exec rails <command> and bundle exec rake <command> from here on in.

Related

Webpacker binstubs not installing correctly

I have a perplexing issue here when trying to implement the Rails Webpacker gem into an existing application.
Unfortunately, I do not have much to offer in the way of debugging information, this is also an internal project, so I have limited options in terms of sharing the entire project source.
I am following the exact steps outlined here: https://github.com/rails/webpacker and have done it multiple times now, but during the bundle exec rails webpacker:install command (after running bundle), I see the message:
Skipped webpack and webpack-dev-server since they already exist.
If you want to overwrite skipped stubs, use --force.
This binstubs most-definitely do not exist in my bin/ directory. Either before or after the webpacker install.
I feel like I have tried everything at this point, and nothing seems to be working:
Reinstalling the gem (multiple versions, even via Git)
Manually creating the binstub from a different project (this "worked" until I tried to run the webpacker:install:react script).
Manually running Yarn, attempting to --force create the binstubs
Tried multiple different configuration tweaks in webpacker.yml
I am just out of ideas at this point. Anything else I should be checking, could try?
This is a fix that worked for me:
I copied these two files into the bin directory of my app and then bundle exec rails webpacker:check_binstubs stopped complaining.
As a side effect it made my app deployable on my Paas with the standard buildpack.

Apparent conflict between bundler and RVM

I'm using rvm with a gemset for a rails project. Normally, installed gems get put in to the my_gemset/gems folder, however it seems that gems sourced from github get put in to my_gemset/bundler/gems. However, because there's a file with the name bundler in the gemset folder, Bundler throws an error:
Bundler could not install a gem because it needs to create a
directory, but a file exists -
/home/me/.rvm/gems/ruby-2.4.1#my_gemset/bundler. Please delete this
file and try again.
Renaming the file allows the bundle install command to complete successfully, so I'm pretty confident the problem is just isolated to this one file. I don't understand Bundler well enough to just go deleting the file though, because it looks like it's doing important stuff.
Can I just delete the file without bad stuff happening? Is there a way to change the directory that gems sourced from github get installed to?
It looks like these file are binstubs that somehow got installed in to the main gemset folder, with duplicates installed to the gemset/bin folder. So probably not necessary to keep? Will be renaming for now.

Bundler is using a binstub that was created for a different gem.

When I run a rails console using
rails console
everything is fine.
When I run a rails console using
bundle exec rails console
I get the following warning
Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub my_gem` to work around a system/bundle conflict.
my_gem happens to be a gem that I've created that is completely unrelated and not used in the current project directory.
I've tried every solution in this question with no luck:
Bundler is using a binstub that was created for a different gem
I would appreciate any guidance on removing this warning or help understanding how binstubs work so that I can figure out what's going on.
Nowadays it's common for projects to have "specialized" versions of tools. E.g. in some projects the "rails" command may be expected to be run using "spring" (to start up faster).
So it's not uncommon to generate files in your project's 'bin' directory, and then use those versions when running commands, so e.g. instead of
bundle exec rails console
or
bundle exec spring rails console
you could simply expect the following to work correctly
bin/rails console
and not care whether the project needs spring or bundler or zeus or whatever.
So if you don't have 'bin/rails' in your project, you should generate one that suits the project, e.g. using
bin/rake rails:update:bin
If you don't already have bin/rake, you might have to use
bundle exec rake rails:update:bin
(so your bin/rake commands will also get a speedup from using spring)
Some people even put ./bin in their paths, so whenever they run rake (or whatever) they are actually running ./bin/rake if it exists.
Troubleshooting
for project specific tasks, use bin/* files, creating them if needed (e.g. using special rake tasks like in Rails or using bundle binstub <gemname>) - usually those have Bundler specific lines that will make Bundler happy.
for non-project gems (like your gem), find out where it is (e.g. which mygem) and check out it's contents - it's probably using e.g. "bundler/setup" which is confusing Bundler (because bundler expects a local Gemfile file). Maybe your gem is using bundler (it shouldn't if it's a "global" kind of tool and not a "project" tool).
Also, if you're using them, check if tools like RVM and .rbenv are correctly adding their stuff to your bin files (they usually need to setup specific paths)
If you still have questions, it's best to post the contents of the bin file causing problems - it's meant to be a plain Ruby file, so if there's something wrong, it's usually because of the file contents (and not anything else).
More info: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs
It happened in a project of mine. Because I ran bundle install with another ruby version.
Make sure your rvm is the correctly ruby version.

"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.

Capistrano user-related problem

I'm deploying a rails application using Capistrano to a shared server (on WebFaction). This means there are several different Ruby version installed there.
Everything works fine until I want to run some rake tasks. These tasks fail by saying I don't have the right RubyGems version.
From this thread I understood that fixing it would be as easy as adding the full path to the correct rake folder to my rake commands. I tried that but failed again, now because the Ruby interpreter that is used is the wrong one.
I assumed that capistrano would use the username/password I gave it to run commands on the server but it seems not to be the case.
Am I missing something? How can I fix that?
Thanks!
This is indeed a path issue. I solved it by symlinking my ruby, rake, and rails executables to my path. For instance, if the executables that you want (but are failing to work) are located at /opt/ruby/bin/ruby, you'll symlink it to:
ln -s /opt/ruby/bin/ruby /usr/local/bin/ruby

Resources