install gem in local machine - ruby-on-rails

I am using pry gem for debugging my rails application. So I have
specified it in my Gemfile and using it. But I dont need to push the
Gemfile with pry gem specified. So everytime I need to revert it to
original Gemfile and push it to remote repo.
I was wondering is there any way where I can install pry gem in my
local machine and use it in my rails app globally so that I dont have
to specify that gem in Gemfile.??
I tried to do
gem install pry
But when I use binding.pry in my rails controller, it says
undefined method `pry' for #<Binding:0x0000000619398>

With bundler you can create groups according to your environments.
You can intall your gem only for the development group.
Put the line below in your gemfile.
gem 'pry', :group => :development

Related

Bundler cannot find `whenever` gem, when deploying using capistrano

I am trying to deploy my app in a staging environment using Capistrano.
Running cap staging deploy results in error saying:
bundler: failed to load command: whenever (/home/ubuntu/builder/shared/bundle/ruby/2.7.0/bin/whenever)
DEBUG [52d26072] Gem::Exception: can't find executable whenever for gem whenever. whenever is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
I have already included whenever gem in the local Gemfile but still it is not able to find it:
Here's a part of my Gemfile:
gem 'capistrano',
gem 'capistrano-secrets-yml'
gem 'capistrano-rbenv'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'whenever', :require => false
I am not able to find what the problem is. Can you please help me?
I would try bundle exec cap staging deploy to make sure you are executing the command using your bundle. Additionally you may need to remove require => false because it does not include the library when you load your bundle.

Rails - how do gems relate to doing 'bundle'

I'm learning Ruby on Rails from Michael Hartl's website. I have a Gemfile that looks like this:
source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
.
.
.
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Why is this sequence of commands correct:
`$ bundle install --without production`
`$ bundle update`
`$ bundle install`
Shouldn't it first be bundle update then bundle install --without production. Why call bundle install twice? I think the second call is redundant.
Why is this sequence of commands correct:
$ bundle install --without production $ bundle update $ bundle install
Without context, it's difficult to answer this—but one can intuit from the commands that it probably doesn't appear as one string of commands to be executed dutifully.
bundle install --without production installs exactly the versions in your lockfile, skipping any gems in a production group or with a production tag. This allows you to install only what you need to test and develop your application. (e.g., you probably don't want to waste lines with your logging service or pollute your monitoring service.) More importantly, this gives you a known-good working state for development on any machine you use.
bundle update updates the lockfile with permissible newer versions of the gems in the Gemfile. This can and will break your application if the Gemfile has not been well-crafted and versions of your dependencies have changed in the mean time. (So to answer your other question, no, you wouldn't run an update before an install.)
bundle install is most likely there to illustrate the correct command for deploying your production application: It wouldn't make any sense to skip the production gems and immediately turn around to install the production gems.
Where actually are these stuff being downloaded saved? Where are they
being installed? On my computer? I never got where they actually go or
hide. Maybe in my applications folder? But where exactly?
On your computer, in your Ruby installation. Ruby, like Perl and Python, maintains a portion of its directory structure specifically for add-on libraries.
In Ruby 2.0.0, for example, they live someplace similar to [RUBY_ROOT]/lib/ruby/gems/2.0.0/gems. For very specific purposes, it's also possible to install them locally in your Rails application's directory.
My recommendation is
1) Just do bundle, forget the rest. Not important to your learning
2) bundle install
OK, so for whatever version of ruby you are currently using this will take your Gemfile and get the right versions of those gems from rubygems.org (the site). and then install those gems on your machine for version of ruby that you are using if that version doesn't already exist on your machine. If the version exist, no download is needed, the gem version will be able to be immediately included, e.g. when offline.
If you switch ruby version then you'll usually need to bundle install again to get the right versions of those gems for the version of ruby that is currently being used on your machine.
If you use a tool such as rvm to manage your ruby versions then this is as simple as:
cd the_application_directory_for_your_rails_application
rvm use 1.9.3
bundle install
then to switch to ruby 2.0
rvm use 2.0
bundle install
You can specify specific ruby versions with
rvm use 1.9.3-p448 # e.g. for the -p448 version
You can see the 'currently available' ruby versions on your machine with
rvm list rubies
You can install a specific ruby with, e.g.
rvm install 1.9.3-p194

Rails 3: Run thin server without gem 'thin' in gemfile

Is it possible to run thin server (gem 'thin') without referencing gem 'thin' in gemfile?
he problem is that on Windows blunder add dependencies in gemfile.lock (eventmachine 1.0.0.beta.4.1 - the only version for windows) that heroku hosting can not accept while push fails.
Try adding that dependency in the development group only in your gemfile:
group :development do
eventmachine, '1.0.0.beta.4.1'
end
That should prevent bundler from trying to install that on heroku.

How do you tell rails to generate integration tests using rspec and webrat?

I'm working through the Ruby on Rails Tutorial and I'm getting stuck on the integration tests. When I try to generate the integration tests for layout_links, I get the following comments in the generated test:
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
And I don't see the "response.should be_success" syntax that I expect. I think I've managed to hose my installation somehow but I don't know how to see which gems I have on the system and how to uninstall/reinstall them.
[edit]I do have webrat configured in the "test" section of my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.5.0'
end
group :test do
gem 'rspec', '2.5.0'
gem 'webrat', '0.7.1'
end
Any help would be greatly appreciated.
I believe that message means that webrat was not detected when the scaffold was generated. Look in your projects Gemfile for:
gem 'webrat'
Add it if it's missing, then run bundle install, then run the generator again.
I've gotten this to work and the problem seems to be my ruby/rails installation. I'm running Ubuntu and I think I've mixed a few packages installed via apt with those installed via bundle and gotten my system confused. I've followed this tutorial on installing Ruby on Rails in Ubuntu using rvm and now I can generate and run my tests again. I'm still having a few issues with autotest which I believe are related to conflicting packages. rvm looks like it's a much better way to set up a rails environment than apt and it allows you to only install your rails environment for one user. This way, you can set up a test user to make sure you get everything configured correctly without changing your entire system.
Thanks for all of the help.

Launching RoR server for an existing app gives error

I just made my first setup of RoR, and creating a new application works fine. But when I want to run the rails server I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.3/lib/delayed/yaml_ext.rb:30:in 'remove_method': method 'to_yaml' not defined in Class (NameError)
I ran the "bundle install" in the app directory and installed all the necessary files (with some problems however, but I excluded the gems with problems in the gemfile) and the last bundle install said that I have successfully installed all the needed packs.
I'm lost and I can't find a similar error on the internet. Can you help me?
EDIT: I forgot to mention that I'm not having a problem with a new application. It's running an existing one (that I didn't build, but works fine for others) that the error is related to. Here's the gemfile for that app:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql'
gem "haml", ">= 3.0.0"
gem "haml-rails"
gem 'simple_form'
gem 'delayed_job'
#gem 'auto_crawlers'
gem 'will_paginate', '~> 3.0.beta'
group :test do
gem 'factory_girl_rails'
gem 'mocha'
end
group :development do
#gem "nifty-generators", "0.4.3", :git => "git://github.com/JonasNielsen/nifty-generators.git"
gem 'fastercsv'
end
gem "mocha", :group => :test
Do you think the error is because I left out the two gems with "#" ? Those were causing problems at first, and I don't think I need them to test some minor changes in the app (some views that I have to modify)
The issue is being described, and supposedly fixed here: https://github.com/collectiveidea/delayed_job/issuesearch?state=open&q=yaml#issue/194
Try this from the command line: irb -rubygems -r delayed_job and then from your bundled directory bundle-exec irb -rubygems -r delayed_job which will show if there is a difference between your system gems and your bundled setup - you might see an error in one or both attempts to run IRB.
If there is an error using bundle-exec but not with your system gems then it's a bundler issue. If not, are you sure the app is designed to function under Ruby 1.9? It looks like to_yaml isn't available at the point DJ is required, which implies it probably needs a require "yaml" somewhere.

Resources