How to check your gem list on heroku - ruby-on-rails

I know the command that works to do this, but I don't understand why. What is `...` doing in this context.
I know I can run:
heroku console
`gem list`
or
heroku console
`gem list`.split("\n")
to get a nice output, but I don't understand what these are doing. Why the ``?

I've updated this in-case someone happens to come across heroku console as it's been disabled.
heroku run gem list
Show gems installed via :git
heroku run bundle show

The back ticks effectively making a system call and return the response that was written to stdout. Take a look at the Kernel ruby docs for more info.

heroku console is basically running an irb console on the remote computer, so you're in a ruby console when you do it. The backticks (`) are a standard way to run a system command in ruby.

In Ruby, you can run a system command either by using Kernel#exec or by placing the contents in backticks. This is the same as typing gem list on the command line and getting the result back as a string.

For example
heroku run 'gem list'
Becouse
heroku console
is removed from heroku

Related

What is the difference between rails console and bundle console?

Can anyone explain me or give me a resource where I can learn the differences between rails console and bundle console? Is there way to load all the gems automatically in irb instead of require gem?
Here is a good explanation: What's the Difference Between irb, bundle exec irb, bundle console, and rails console?
irb is the basic Ruby console. It ignores your Gemfile, and only core
Ruby classes are accessible without require-ing them. It can’t easily
load gems that Bundler installs outside of RubyGems’ load path.
bundle exec irb is like irb, if you also required bundler/setup. You
can only easily require gems that are in your Gemfile.lock, but you
can load those gems no matter where Bundler put them.
bundle console is like bundle exec irb, if you also called
Bundler.require. All of the gems in your Gemfile, except the ones
marked require: false, can be used without requiring them. It’s really
convenient when you’re writing your own gems, or working on non-Rails
code.
rails console is like running bundle console inside a Rails app, if
you also required config/environment.rb. You can play with your entire
Rails app, autoloads and database connections work, and everything’s
hooked up the way you’d expect. If you’re working in a Rails app, this
is the most helpful kind of console.
The answer from Aleksandr is great.
I just wanted to add there is also the option for running
bundle exec rails console
which combines everything from rails console and bundle exec irb answer from Aleksandr's answer.

RhoStudio build for iOS7 Simulator: "Gem rake not installed" error

I am trying to build a RhoStudio application for the iPhone-simulator on Mac OS X 10.9.1.
The build with XCode fails at
/bin/sh -c ~/.rvm/gems/ruby-1.9.3-p545/gems/rhodes-4.0.1/platform/iphone/build/rhorunner.build/Release-iphonesimulator/rhorunner.build/Script-5C0442920EFBE79D0014E5C6.sh
[31mERROR: Gem rake is not installed, run `gem install rake` first. (B [m
Command /bin/sh failed with exit code 127
Within the script (Script-5C0442920EFBE79D0014E5C6.sh), there is a "source ~/.profile" call which seems to mess up the environment for rake. The error can be reproduced by opening a shell and executing the source command. If i don't source, there is no error for rake.
Also, if i try to gem install rake after the source command, there is a confirmation that it has been installed but the error still occurs.
Anybody help?
This is one of those issues where there are way too many specific factors involved to easily come up with a solution; I'm going through the ropes myself with Rhodes in 10.9. The problem is because Rhodes constantly is changing environments (it's a real mess) so your environment, which tracks the paths to your Ruby installations and Gems, will be very volatile. Here are some tips that might help you diagnose the issue:
Try running gem which rake, which shows you the absolute path of your rake gem as visible to the calling script. You can place this in one of your config files like ~/.profile or ~/.bashrc to test different contexts.
You can also use gem env to see a full printout of the gem's configuration for your environment, and just plain env shows you the system (shell) environment. Look very closely for the variables GEM_PATH AND GEM_ROOT which show you where Rubygems and your gem libs are searched for, respectively.
Keep in mind using sudo before install will affect where your gems are installed; this depends on where you installed Ruby, which ruby manager (for RVM look in ~/.rvm) and whether or not you are using Bundler for instance.
Hope that helps. Also, if you are into Bash scripting I recently posted a tip for managing the environment paths that might help: https://coderwall.com/p/f_dlyg

how do I add a gem in heroku?

I updated a gem(rtf) in my ruby on rails app through the Gemfile. The app works fine on my localhost but when I pushed changes to heroku and tried 'bundle install' within heroku bash. I see that the gem has been installed based on the log
Using rtf (0.3.3)
Following this, I did a
heroku restart --a myapp
however, when i tried the app on heroku, it still cant recognize the lib installed through the gem, i get the following error(normally appears when the library cannot be reached for command "require 'RTF'").
cannot load such file -- RTF
What am I doing wrong in heroku?
I think you misunderstand how Heroku works. When you run a bash shell on your app, nothing you do on that dyno will affect any other dynos for your app (like your web dynos). Heroku runs bundle install for you when you deploy your app and if your Gemfile is configured correctly all the gems will be installed.
the answer by sevenseacat is right- i had just got the case wrong-
require 'rtf'
works fine. In OSX, it ignores case in the command require 'RTF'

Rails could not find gem, found in bundle show

So if I try to start my server I get the error
Could not find abstract-1.0.0 in any of the sources
Try running bundle install.
I run that and I get
Using abstract (1.0.0)
Furthermore running a bundle show abstract gives me the correct path for the gem. That path is also referenced in gem env.
I'm really not sure how it can't be found...
You might have conflicting installations of ruby. One with the proper gem which you are using in the shell but one the server is using which doesn't have it installed properly.
I would check your environment variables to see if there is a conflict.
This can also happen if you are using RVM and have switched to a different version/gemset than the default one.
What command are you using to start the server?
If rails server is what is giving you the error, I recommend trying: bundle exec rails server
If that's not the issue, another question that might help troubleshoot; are you using rvm? What does rvm info give you?

Rails and Rake commands hang and do nothing at all

I don't know why but when I run rake commands in my rails project, nothing happens. Also rails server does nothing. Any suggestions?
you can add an "ruby -rtracer" to the begining to see where it is hanging.
The solution for me entailed exiting rails console -sandbox.
I think sandboxing console puts a lock of some sort on the database.
You could try adding the --trace argument to your rake calls to see if that sheds any light on where it is getting stuck. Failing that there may be some information in the logs.
It does suggest that something that is getting stuck during setting up your environment which may be something you've added to environment.rb.
Are you using rvm?
A lot of advice these days is to install ruby within rvm and rails within an rvm gemset. If you've done this, then you need to remember to do commands such as these at the start of your terminal session:
rvm use 1.9.3
rvm gemset use ruby193rails3
I found if I forgot to do this, then the rake command, even just a simple rake --version , would hang and thrash the disk.
...which all seems a bit fragile. I guess it's latching onto part of rails but with some files missing due to rvm not having moved them into place or something.
Spring has a bug in Rails 4.1 which also causes this (not the OP's issue, based on date). For those googling, I solved this problem my typing "spring stop". Spring will be automatically restarted the next time you run "rails ". To give proper credit, I found this information from this blog:
http://www.dixis.com/?p=754
What fixed this for me was running
bin/spring stop
and then running my rake command after.

Resources