debug rails 3.1.1 application - ruby-on-rails-3

I'm try to add a debugger to my rails 3.1.1 application which uses ruby 1.9.2. I have added the following to my gemfile:
gem 'ruby-debug19', :require => 'ruby-debug'
and I get the following error:
/.rvm/gems/ruby-1.9.2-p290#rails31/gems/ruby-debug19-0.11.6/cli/ruby-debug/interface.rb:55:in `block (2 levels) in initialize': uninitialized constant Debugger::LocalInterface::Readline (NameError)
by the way i have the following:
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
$ rails -v
Rails 3.1.1
$ rvm -v
rvm 1.8.6 by Wayne E. Seguin (wayneeseguin#gmail.com) [https://rvm.beginrescueend.com/]

What made is work for me is:
sudo gem install ruby-debug19
gem install linecache19
gem install ruby-debug-base19
bundle update
rails server -u

Did you install all the prerequisites listed in rvm notes before you installed Ruby? I'm not positive, but I think readline is a dependency for MRI on Linux.
You may also follow these instructions from the RVM site:
If you have an error when compiling pertaining to readline, you may
need to attempt installing with the procedure defined below.
NOTE: Before you follow the procedure below please be sure to verify
that you have installed any dependencies for the Ruby you are
installing listed by the 'rvm notes' command. If you have not yet done
that do so then run 'rvm remove X ; rvm install X' where X is the Ruby
that you are concerned with.
$ rvm pkg install readline
$ rvm remove 1.9.2
$ rvm install 1.9.2 --with-readline-dir=$rvm_path/usr

Related

Ruby cannot find gem in gemset

I apologize if I've missed something obvious. I am new to Ruby.
My overall goal is to add functionality to an existing script, which is using rvm and gemsets.
When I install new gems to a particular gemset, the requires in my scripts fail to find them. I am using the following rvm instance:
$ rvm current
jruby-1.6.7.2#preflight
To confirm:
$ which ruby
/Users/user/.rvm/rubies/jruby-1.6.7.2/bin/ruby
$ ruby -v
jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.8.0_11) [darwin-x86_64-java]
I specified the gemset into I install a given gem (let's say xml-simple).
$ rvm #preflight do gem install xml-simple
Successfully installed xml-simple-1.1.5
1 gem installed
To verify the gem installed correctly:
$ gem list
*** LOCAL GEMS ***
...
xml-simple (1.1.5)
...
We see the module I installed there.
Following the xml-simple instructions to include the module, I run this script:
require 'xmlsimple'
which, results in:
$ ruby testver.rb
LoadError: no such file to load -- xmlsimple
require at org/jruby/RubyKernel.java:1033
(root) at testver.rb:1
One suspicious thing I have seen is that printing out RUBY_VERSION and $LOAD_PATH shows me this:
$ ruby testver.rb
1.8.7
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/site_ruby/1.8
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/site_ruby/shared
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/1.8
.
Adding require "rubygems" is required prior to Ruby version 1.9.2, per this stackoverflow answer. This resolved my issue.

Clean install Spree 1.1.1 goes fine, not so for Spree 1.1.2

I use the following steps to install Spree version 1.1.1,
rvm use ruby-1.9.2-p318#my_spree_shop --create
gem install rails -v 3.2.3 --no-ri --no-rdoc
gem install spree -v 1.1.1 --no-ri --no-rdoc
rails new my_spree_shop -d postgresql
cd my_spree_shop
open config/database.yml # modify database settings
rake db:create
spree install # 'Enter'ing all defaults
This works, but the admin pages suggest to have version 1.1.2 because of a security vulnerability. Doing the same steps for spree 1.1.2 with Rails 3.2.6, will result in the following error at the last step:
precompiling assets
/Users/~/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /Users/~/.rvm/gems/ruby-1.9.2- p318#global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
couldn't find file 'admin/spree_auth'
(in /Users/~/Development/spree_pixelhobby/app/assets/javascripts/admin/all.js:9)
What should be done differently for Spree 1.1.2 ?
This issue is happening because the wrong version of Spree is being installed when you run bundle install.
Specify the correct dependency in your Gemfile like this:
gem 'spree', '1.1.2'
And then run bundle install again.
Well, you do have to add gem 'spree', '1.1.2' to your Gemfile, but you have to remove it also after the bundle update, or you will get some other issues, later during spree install.
All steps for a clean install for Spree 1.1.2 & Rails 3.2.6
rvm use ruby-1.9.2-p318#my_spree_shop --create
gem install rails -v 3.2.6 --no-ri --no-rdoc
gem install spree -v 1.1.2 --no-ri --no-rdoc
rails new my_spree_shop -d postgresql
cd my_spree_shop
Addition compared to installing Spree 1.1.1
echo "gem 'spree', '1.1.2'" >> Gemfile # adding spree to the Gemfile
bundle update
sed -ie '$d' Gemfile # removing the line you just added.
edit your db configurations and create the databases
vi config/database.yml
rake db:create
rake db:create RAILS_ENV=production
And finaly:
spree install

Can't remove bundler in RVM

I have 1.9.2 Ruby installed in RVM. When I do a gem list I get this:
bundler (1.1.3)
When I try to remove it I get:
gem uninstall bundler
INFO: gem "bundler" is not installed
When I try to run bundle install for my app I get:
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (= 3.0.1) ruby depends on
bundler (~> 1.0.0) ruby
Current Bundler version:
bundler (1.1.3)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?
I have tried uninstalling 1.9.2 but that did not help.
Found the answer in another Stack thread but closed it without noting the link. The issue is that rvm will not let you uninstall gems from a custom gemset that are still a part of the default "global" gemset. Do a rvm gemset use global then uninstall 1.1.3 from global.
Running 'sudo gem uninstall' did the trick for me. It seems that 'gem uninstall' will sometimes "lie" when not running as sudo.

Can RVM hide a gem from the global gemset?

The project I'm about to work on asks for version 1.0.10 of bundler and version 0.8.7 of rake. My global gemset has slightly newer versions of these gems. I.e., the install instructions for the new project look like this:
rvm gemset use rails3
gem uninstall -x bundler
gem install bundler -v 1.0.10
gem uninstall -x rake
gem install rake -v 0.8.7 # Rake needs to be at 0.8.7
What happens is that when I'm in this new rails3 gemset I can't uninstall the existing gems (and personally I don't want to) because they exist in the global gemset.
So, question: can I somehow hide those two gems that exist in the global gemset?
I can list the gems:
$ gem list
*** LOCAL GEMS ***
addressable (2.2.6)
archive-tar-minitar (0.5.2)
awesome_print (1.0.1)
bundler (1.0.21, 1.0.10)
...
rake (0.9.2.2, 0.8.7)
...
Maybe an ancillary question would be: since I have installed the older versions into the the rails3 gemset, will rvm prefer those because the fact they were specifically installed somehow overrides the version in global, or will rvm take the gems with the highest version number?
any command except bundle should be prefixed with bundle exec and this will assure proper version of gem is used (using Gemfile)
you can avoid writing always bundle exec by using my gem rubygems-bundler
for running bundle command - rubygems will select latest available version if you do not specify one ex. bundle _1.0.10_ exec rake db:create

I can't seem to get rails installed on my Mac (10.6.5). Following Ruby on Rails Tutorial 3

I'm trying to get Rails 3 up and running by following the steps outlined in "Ruby on Rails Tutorial" by Michael Hartl (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book).
The details start in section 1.2.2 (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:rubygems). Here you go through the following steps:
Installing Git
Installing Ruby (version 1.9.2) using Ruby Version Manager (RVM)
Creating different gemsets for environments using Ruby 1.8.7 and 1.9.2
Installing RubyGems
and finally, installing Rails.
I run the following command [sudo] gem install rails --version 3.0.7
Everything seemed to install correctly (based on no errors). However, when I type "rails -v", rails cannot be found.
I am a Rails newbie. I'm trying to install Rails on a machine running Mac OS X 10.6.7.
Thanks.
If you are using RVM you probably don't want to use sudo when installing gems. If you have Git installed only steps needed to get Rails are:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.zshrc
# Reload your shell now (open a new terminal for example)
rvm install 1.9.2
rvm 1.9.2 --default
gem install rails --version 3.0.7
hash -r
This skips the gemsets part (you don't need it if you are just starting learning Rails) and assumes that you use Zsh (I think it's Mac OS X default, if you use Bash then you have to alter .bashrc, not .zshrc).
If you want to remove your previous installation and start over use rvm implode.