Checking out from GitHub a specific reference within a Ruby Gemfile - ruby-on-rails

So, I have no Ruby experience at all. However, I'm being asked to look after some Ruby on Rails / Ruby source code that was left behind by my predecessor. I'd like to at least get it to install and run within its Docker container.
From what I can tell, it is failing because of the mimemagic problem from a couple of years ago. It has a dependency on mimemagic v0.3.0 . I know the right thing to do would be to move on to the recent versions that have not been yanked. But, with my limited experience with Ruby, I'd like to at least get my predecessor's code to install and run.
Since moving up to the earliest mimemagic that is available (v0.3.7) appears to break other things, I have been trying to install v0.3.0 using the GitHub reference as a work around.
This:
gem 'mimemagic', github: 'mimemagicrb/mimemagic', ref: 'a4b038c6c1b9d76dac33d5711d28aaa9b4c42c66'
complains that I'm transmitting without encryption. It ultimately fails to fetch with a connection time out.
Meanwhile, this:
gem 'mimemagic', git: 'git#github.com:mimemagicrb/mimemagic.git', ref: 'a4b038c6c1b9d76dac33d5711d28aaa9b4c42c66'
complains that the host key verification has failed.
Finally, this gets me a little further:
gem 'mimemagic', git: 'https://github.com/mimemagicrb/mimemagic.git', ref: 'a4b038c6c1b9d76dac33d5711d28aaa9b4c42c66'
but an error later on looks like this:
rake aborted!
Bundler::GitError: The git source https://github.com/mimemagicrb/mimemagic.git is not yet checked out. Please run `bundle install` before trying to start your application
I have this feeling that "quickly getting it to work" isn't a reality and perhaps all of this will take a lot more than the 1-2 days I've spent so far. I just would like to check what the correct gem/git commands are, and if any of the above three are close.
Thank you!

As the error suggests, you must run the bundle install command before starting the application server or accessing the console.
The reference in the Gemfile is added correctly.
gem 'mimemagic', git: 'https://github.com/mimemagicrb/mimemagic.git', ref: 'a4b038c6c1b9d76dac33d5711d28aaa9b4c42c66'
If you've already executed the mentioned command, can you update the question to have the output for this command?
P.S. Read more about the bundle install command here.

Related

CircleCI says Your bundle could not be found in any of the sources listed in your Gemfile

CircleCI install dependencies error:
Your bundle is locked to my_cool_gem (0.7.2), 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 my_cool_gem (0.7.2) has removed it. You'll
need to update your bundle to a version other than my_cool_gem (0.7.2) that
hasn't been removed in order to install.
Screenshot of CircleCI output:
CircleCI can't find a gem that I published to GitHub Packages, yet I have no such problem in local development.
I have qualifying versions of RubyGems and Bundler, as per GitHub's docs - https://docs.github.com/en/free-pro-team#latest/packages/guides/configuring-rubygems-for-use-with-github-packages - and I believe I have followed the instructions to publish and use said published gems... and, again, usage works locally but fails in CircleCI...
RubyGems version:
-bash> gem --version
3.0.9
Bundler version:
-bash> bundle --version
Bundler version 1.17.3
Gemfile:
source 'https://rubygems.org'
source 'https://rubygems.pkg.github.com/my_cool_org'
gem 'my_cool_gem', '0.7.2'
Note that I have also tried:
source 'https://rubygems.org'
source 'https://rubygems.pkg.github.com/my_cool_org'
source 'https://rubygems.pkg.github.com/my_cool_org' do
gem 'my_cool_gem', '0.7.2'
end
Try running bundle update my_cool_gem if it modifies Gemfile.lock that should fix it.
Have you verified that it's actually still available at the source? I know you said it works locally, but that could be because of local cached versions of the gem. Bundle won't try to install something that's already there.
You might be able to verify this by uninstalling it locally and running bundle install again.
Ensure that you've correctly set the environment variable for authenticating with rubygems.pkg.github.com.
(Though the variable may be set, the value may be incorrect - as was the case for me.)
Interesting, sounds like a image bug. What happens if you try to list all available versions of your gem? gem search ^gem_name$ --all?
Have you tried to force update beforehand? sudo gem update --system
For me, the problem was that access tokens was different on local machine and on CI. And the key on CI was valid, but it had no permission for specific repository containing requested gem.
Despite Github provides single registry per organization, gems are associated with company's repositories. And packages within registry will be visible or invisible depending on permissions to these repositories that access tokens have. For example, user can have access to some repositories of organization and don't have to others — if using that user's personal access token, only gems associated with permitted repositories will be visible. Others will be hidden, so the error is "that version cannot be found".
I ran into this again, and this time I could not solve it with the solution I used last time, and no other solution worked either, so instead I chose to temporarily work around the issue by placing a copy of the gem in question directly into my app (a process known as "vendoring"; see this, this, and this):
gem unpack my_cool_gem # note, I actually had to specify the version with -v 0.12.1
mkdir vendor/gems/
mv my_cool_gem-0.12.1 vendor/gems/
In Gemfile, use the :path option rather than :source:
gem 'my_cool_gem', '0.12.1', path: 'vendor/gems'
Then generate Gemfile.lock:
bundle install

Cannot access function in latest version of GitHub gem

I am trying to use the MindBody Gem but when I attempt to run: $ gem install mindbody-api I see the error:
$ gem install mindbody-api
ERROR: Could not find a valid gem 'mindbody-api' (>= 0) in any repository
I've been able to get it working in my gemfile by including the path of the GitHub page: gem 'mindbody-api', :git => 'git://github.com/wingrunr21/mindbody-api.git' and I am successful when I run bundle install but I've noticed that my version is missing a function that is present in the GitHub Repo, specifically:
MindBody::Services::SaleService.checkout_shopping_cart(search_creds)
NoMethodError: undefined method `checkout_shopping_cart' for MindBody::Services::SaleService:Class
despite the function being listed on the GitHub repo SaleService page. Any idea what I should try next?
In your comment under the question it shows that you have older version of the gem:
rvm/gems/ruby-2.2.3#awaken/bundler/gems/mindbody-api-579af18314d2.
So if you browse the repo at this point of time (579af18314d2) you will see that the method does not exist yet - link
In order to fix it you need to update it to thelatest version, which you can do by:
bundle update --source mindbody-api
Also to verify that you have the latest version when you do bundle show mindbody-api it should show something like: .rvm/gems/ruby-2.2.3#awaken/bundler/gems/mindbody-api-f58110f2b255
Regarding the install:
The only version released is an alpha release, that's why you can't install it. You can, however, install the alpha version with:
gem install mindbody-api -v 1.0.1.alpha
Regarding the method missing:
It appears there is a bug in the way the operations are loaded. I was able to get the method loaded under certain circumstances (cloning & building myself, I think) but even then the behavior wasn't consistent.
The gem hasn't had any significant major updates in a few years. It's not clear if the gem is maintained but I think your best bet might be to create a github repo issue, or fork & fix it yourself.

My gem commands keep pointing to a wrong server

Any time I run a gem command (gem install, gem list, etc) I get the following error:
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ENETUNREACH: Network is unreachable - connect(2) (<internal_server_at_work>)
A while back, before I finally got around to learning Rails, one of the developers made a gem for a project and I made some sort of change to add that server to my gem repositories.
I have no idea where that is. My Gemfile in the project I'm using to teach myself Rails puts rubygems.org as the source. Is there a master Gemfile of some sort?
Thanks
The Gemfile.lock specifies some of this information. Deleting it and rerunning bundle install may resolve the problem.
You can always try bundle update gem_name. Also, it is possible to point it to the exact URL.
gem some_gem, :git => "another url"
You could also paste your Gemfile for us to help you out better. :)

Not able to view site in browser with railsinstaller due to missing Gem

I am super, super new at programming and I have been trying to get everything set-up on my computer. I have installed RailsInstaller, go to >railsinstaller_demo, and type in rails s. I get the following error though could not find gem 'uglifier <>= 1.0.3> x86-mingw32'
I looked through the forum and found how to do a gem list and i noticed it was not there. I then went to gembundler and ran $ gem install bundler. I tried again but it did not work.
I am sure the answer is on this site, but i am so new that i see all these lines of code I actually have no idea where to type it in.. I am running Windows 7.
thanks for taking the time to help out a real beginner.
Have you gone to the $ railsinstaller_demo directory and run the bundle install command? This will install the gem dependencies for the application; you will not be able to run the server until you've bundled the gems. Additionally, if you're still having issues with the uglifier gem, go ahead and remove the line in the Gemfile and then run bundle install
If you need further help with the Command Prompt, you an find out more at http://bit.ly/ZajVeW.
Thanks,
Evan

I don't completely understand the gemfile in a rails application

What is the difference between installing a gem from the command line
sudo gem install gem-name
and writing your gem into the Gemfile and running bundle install?
I think the problem is that I don't understand the exact purpose of the Gemfile. So far it seems like it is a place to list all of the gems that your app is dependent on.
Installing a gem via:
sudo gem install gem-name
is going to install that gem system wide.
Whereas installing them via the Gemfile is specific for your rails app(to keep track of dependencies, version, app portability etc).
The best source of the whats and whys about Bundler, is probably this page:
http://gembundler.com/rationale.html
That page has great examples and explanation about why Bundler is useful and in some cases, necessary.
I always thought you write all gems that your app is dependent on in it, and then if you want to port your application somewhere else, you can run the bundle install and it'll grab the gems you need for you so you don't manually have to do it.
This might clear things up, I quote:
'It holds information about all the project dependencies so that you don't need to struggle to figure out what gems you need to install.'
http://blog.despo.me/42762318

Resources