I have a mystery to solve when upgrading our Rails3.2 Ruby 1.9 app to a Rails3.2 Ruby 2.1.2 one. Nokogiri seems to break, in that it changes its behavior using open-uri. No gem versions are changed, just the ruby version (this is all on OSX Mavericks, using brew, gcc4 etc).
Steps to reproduce:
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin13.1.0]
$ rails console
Connecting to database specified by database.yml
Loading development environment (Rails 3.2.18)
> feed = Nokogiri::XML(open(URI.encode("http://anyblog.wordpress.org/feed/")))
=> #(Document:0x3fcb82f08448 {
name = "document",
children = [
..
> feed.xpath("//item").count
=> 10
So all good! Next, after a rvm change to Ruby 2.1.2 and a bundle install..
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
$ rails console
Connecting to database specified by database.yml
Loading development environment (Rails 3.2.18)
> feed = Nokogiri::XML(open(URI.encode("http://anyblog.wordpress.org/feed/")))
=>
> feed.inspect
=> "#<Nokogiri::XML::Document:0x86a1f21c name=\"document\">"
> feed.xpath("//item").count
=> 0
So it looks like the 'open' encoding has changed, in that a gzip http stream isn't being fed correctly to nokogiri? I checked with a nokogiri -v and it is using the packaged xml libs rather than system ones. Is this a open-uri Ruby 2.1.2 issue?
Another theory is that one of the gems has monkey patched open-uri to fix something in 1.9 and that is breaking 2.1? Help or ideas please!
EDIT: Here's more info not using Nokogiri, i.e. thinking this is more a open-uri issue on Ruby 2.1.2:
> open(url) {|f|
* f.each_line {|line| p line}
* p f.content_type
* p f.charset
* p f.content_encoding
* }
"\u001F\x8B\b\u0000\u0000\u0000\u0000\u0000\u0000\u0003\xED\x9D\xDBr\eW\xB2\xA6\xAF\xED\xA7\xA8\xCD\u001E\xB7/$\u0010..
(snip)
3\xF3\xA79\xA7\xFAɗ\xFF\u000F\xEAo\x9C\u0014k\xE8\u0000\u0000"
"text/xml"
"utf-8"
["gzip"]
=> ["gzip"]
..the 1.9 version was readable, i.e. gzip was applied already.
If I go into a clean ruby irb it works ok, so it must be something in my rails gems that is changing the behavior of open-uri open to not deflate/gzip. I have a lot of gems referenced.. :(
Ok, here's an answer, and maybe the answer. Ruby 2 changed how it uses headers in HTTP requests and zipping/deflating, but at some point they changed their minds back and put it to be how 1.9 worked. In the interim some Rails gem maintainers monkey patched HTTP:Net to make their gems work on both 1.9 and 2.0. Those monkey patches still linger in older versions of gems and cause issues like I saw upgrading from 1.9 to 2.1
A summary of the issue and solution here:
http://avi.io/blog/2013/12/17/do-not-upgrade-your-rails-project-to-ruby-2-before-you-read-this/
We use the gem right_aws, and the details of that issue with ruby versions is here:
https://github.com/sferik/twitter/issues/473
The solution was to undo the monkey patch using this as a gem reference in our Gemfile:
gem 'right_http_connection', git: 'git://github.com/rightscale/right_http_connection.git', ref: '3359524d81'
Background reading and more info:
https://github.com/rightscale/right_aws/issues/167
Related
ANSWERED (other noobs should read what I did):
Thanks to those who answered, but I think I know why it had still been defaulting to the system ruby earlier. I started a shell session and installed rbenv, then install ruby-build for rbenv, then install ruby 2.1.2 and ran rbenv global 2.1.2 Then I installed the new version of rails and tried to create a new rails project.
I think the mistake was just that I hadn't started a new shell session and so it defaulted to the rails location it had when the session started, which was with the system ruby. Stupid mistake. Blah.
ORIGINAL POST:
These are my rbenv versions
system
* 2.1.2 (set by /home/ab/.rbenv/version)
and this is what I get when I run
gem list -d rails
rails (4.2.0.beta1, 4.1.1)
Author: David Heinemeier Hansson
Homepage: http://www.rubyonrails.org
License: MIT
Installed at (4.2.0.beta1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
(4.1.1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
The Hartl tutorial online uses 4.2.0beta1, so I want to use that, but when I try to make a new rails project, it defaults to 4.1.1.
Somebody from this suggested a way to change a default rails version, but the command looks in the wrong location. See here
ab#abpc:~/Code/RailsTutorial$ rails _4.2.0beta1_ -v
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (= 4.2.0beta1) amongst [actionmailer-4.1.1, actionpack-4.1.1, actionview-4.1.1, activemodel-4.1.1, activerecord-4.1.1, activesupport-4.1.1, arel-5.0.1.20140414130214, builder-3.2.2, bundler-1.3.5, coffee-rails-4.0.1, coffee-script-2.2.0, coffee-script-source-1.7.0, diff-lcs-1.2.5, erubis-2.7.0, execjs-2.1.0, hike-1.2.3, i18n-0.6.9, jbuilder-2.0.7, jquery-rails-3.1.0, json-1.8.1, libv8-3.16.14.3-x86_64-linux, mail-2.5.4, mime-types-1.25.1, mini_portile-0.6.0, minitest-5.3.4, multi_json-1.10.1, net-http-persistent-2.9, nokogiri-1.6.2.1, polyglot-0.3.5, rack-1.5.2, rack-protection-1.5.3, rack-test-0.6.2, rails-4.1.1, railties-4.1.1, rake-10.3.2, rdoc-4.1.1, rdoc-3.9.4, ref-1.0.5, rspec-2.14.1, rspec-core-2.14.8, rspec-expectations-2.14.5, rspec-mocks-2.14.6, rspec-rails-2.14.2, sass-3.2.19, sass-rails-4.0.3, sdoc-0.4.0, sinatra-1.4.5, spring-1.1.3, sprockets-2.11.0, sprockets-rails-2.1.3, sqlite3-1.3.9, therubyracer-0.12.1, thor-0.19.1, thor-0.18.1.20140116, thread_safe-0.3.4, tilt-1.4.1, treetop-1.4.15, turbolinks-2.2.2, tzinfo-1.2.0, uglifier-2.5.0, webrat-0.7.3] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /usr/local/bin/rails:22:in `<main>'
I'm still far from as knowledgeable as I'd like to be, but I can see that "rails" is defaulting to usr/lib/bin/rails and I need to reroute it to ~/.rbenv/versions/2.1.2/lib/ or somewhere around there... not entirely sure where, and I don't know how to get it to do that. Help?
It looks like you are using your system ruby v1.9.1 which is not compatible with rails 4 at all (Rails 4 requires 1.9.3 or higher).
So first you need to set your ruby version using rbenv global 2.1.2 to set it system-wide or rbenv local 2.1.2 if you just want it for this project. I'm not sure if your system will then default to rails-4.1.1 or the newer beta but you can try rails -v to find out. If not, rails _4.2.0.beta1_ new myapp should work.
The Hartl tutorial online uses 4.2.0beta1
Here is what I am seeing:
Install Rails
Once you’ve installed RubyGems, installing Rails should be easy. This
tutorial standardizes on Rails 4.0, which we can install as follows:
$ gem install rails --version 4.0.8
...
but when I try to make a new rails project, it defaults to 4.1.1.
Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=sample_app2_gems
gem 'rails', '4.0.8'
...
Set the version of rails you want to use in your Gemfile.
I am using rails 4.1.4, ruby 2.1.2 and rvm.
Gemfile (extract)
gem 'rails-perftest'
gem 'ruby-prof', group: :test
I installed ruby using these commands (in order to apply patch which enables memory profiling)
rvm get stable
rvm reinstall 2.1.2 --patch railsexpress
But still no luck and memory reports are empty with rake test:benchmark or rake test:profile
I was trying to get the same Ruby patch and version working with a Rails 3 benchmark and that was broken too, albeit in a different way. It looks to me like this is an oversight in Rails. I'm seeing this warning string on a Rails 3.2 app
$ bundle exec rake test:benchmark
Update your ruby interpreter to be able to run benchmarks.
$ bundle exec rails -v
Rails 3.2.21
The problem seems to be that ActiveSupport 3.2 isn't aware of Ruby versions higher that 2.0 for this particular piece of code
if RUBY_VERSION.between?('1.9.2', '2.0')
require 'active_support/testing/performance/ruby/yarv'
elsif RUBY_VERSION.between?('1.8.6', '1.9')
require 'active_support/testing/performance/ruby/mri'
else
$stderr.puts 'Update your ruby interpreter to be able to run benchmarks.'
exit
end
see https://www.omniref.com/ruby/gems/activesupport/3.2.12/symbols/ActiveSupport::Testing::Performance::Metrics::CpuTime#line=145
After editing the version check manually I can confirm that the patch does work in Rails 3 with version 2.1.2. Perhaps you could check your RUBY_VERSION and RUBY_ENGINE constants for anything unusual?
(I understand this isn't really an answer but I don't have enough reputation to comment. Also it hopefully rules out the rvm patch and ruby-prof as a problem)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
ruby-debug with Ruby 1.9.3?
I had heard rumors that ruby 1.9.3p125 has a solution for the ruby-debug19 problem, so per instructions on the RVM site, I reinstalled 1.9.3:
$ rvm reinstall 1.9.3 --patch debug --force-autoconf
$ ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.2.0]
Then:
gem install ruby-debug19
Added this entry to my Gemfile:
gem 'ruby-debug19'
Then:
$ rails server -u
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
Exiting
To get past this error I changed my Gemfile entry to:
gem 'ruby-debug19', :require => 'ruby-debug'
Now a new error from the server:
/Users/don/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require': dlopen(/Users/don/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.bundle, 9): Symbol not found: _ruby_threadptr_data_type (LoadError)
Referenced from: /Users/don/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.bundle
Expected in: flat namespace
in /Users/don/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.bundle - /Users/don/.rvm/gems/ruby-1.9.3-p125/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.bundle
I'm very confused by the hundreds of posts out there on how to handle this ruby-debug19 issue. I was hoping it had been solved. Apparently not. Any suggestions? (If anyone suggests a patch, please provide step by step instructions on how to apply it. I've struggled with patches in the past.)
A fork of ruby-debug just called 'debugger' now exists that incorporates many of the fixes people had been deploying on top of ruby-debug19, so you should be able to just change your Gemfile to
gem 'debugger'
... and off you go.
Long story short: it's not resolved, and official resolution will only come with a new version of ruby-debug19 or ruby-debug-base19. It's pretty aggravating, I know.
I've done a lot of digging on this, too, and I've kept an eye on things since 1.9.3 came out (because we'd love-love-love to use it in production). However, sadly, 1.9.3-p125 doesn't have a fix for ruby-debug. Only ruby-debug19 will have the fix for ruby-debug19, as the authors of ruby-debug19 and ruby-debug-base19 have been working on a patch and have an updated test build working on Ruby 1.9.3… but they haven't released it to the general public. ruby-debug-base19 hasn't seen a release in eons; ruby-debug19 even longer (since '09).
If you're on rvm head, you should be able to install 1.9.3-p125 with the added "falcon patch" found here (and noted about RVM here. This gist seems to have better instructions (it's a newer fork of the older one).
The best thing to do is just use pry. Its an irb-like replacement for ruby-debug and it works with all version of Ruby with no nasty patching!
https://github.com/pry/pry
You must pass the --with-ruby-include and point it at your src directory for this to work.
(most of these answers elsewhere on SO have gone stale since 1.9.3-p125.)
I've written up new instructions here for ubuntu 11.10 that work on my machine, but give them a try on darwin and see if they help?: https://gist.github.com/2218661
I've been having similar problems using Rails 3.2 with Ruby 1.9.3p0 debugging in Aptana.
For me, new ruby-debug-base193 does not compile. But what works fine is a fix that has been posted elsewhere:
Gemfile:
gem 'ruby-debug-ide19'
gem 'ruby-debug-base19'
And then providing the missing is_binary_data? method somewhere. I put it in my Rails application.rb file like so:
class String
def is_binary_data?
( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
end
end
TLDR: How do I force a rails app to use the correct ruby interpreter?
Hello,
Something hosed parts of my Ruby 1.9.2p290 install (certain classes just went missing one day), so I removed it and attempted to reinstall the environment.
I'm running on Snow Leopard.
Ruby 1.9.2 was installed from source. (I tried to install via MacPorts and it would fail). I am not keen on RVM as I use bundler and I seem to recall some problems with how bundler and RVM interact, though from what I can tell RVM works.
After reinstalling a few gems I noticed they were being placed in a gem folder for Ruby 1.8. "This is weird," I thought.
Starting up the rails app, I notice a lot of weird exceptions being thrown regarding syntax. After printing RUBY_VERSION to stdout, I noticed that the Rails app is running 1.8.7.
which ruby shows only one ruby interpreter:
$ which ruby
/usr/bin/ruby
$ /usr/bin/ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
If I open up Activity Monitor, the ruby process from the Rails app lives at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby, which I believe is the ruby interpreter that OSX shipped with.
I haven't found any information on completely purging Ruby from OSX. I would love to do that then simply install ruby from source.
It seems there are two problems:
Rails is running a ruby interpreter that I have no idea how it is calling, when I need it to run the 1.9.2 interpreter installed from source
gems are being installed in a 1.8 folder, I suspect because gem thinks its running under 1.8
How do I fix this?
Thank you,
Tom
I guess the best way to overcome this issue is using rvm to handle your Ruby and Rails environments through 'gemset's.
I had the same issue and I use gemsets now without a problem.
This is the article which I got things working:
http://stjhimy.com/posts/10-five-quick-steps-to-set-up-rvm-with-rails-2-and-rails3
I'm not sure exactly what I did but I messed up the Ruby/gem harmony trying to get an older 2.3.5 Rails app working on my system.
I'm currently using Ruby 1.9.2-p0 and rubygems 1.5.7. I've tried the newest one 1.8.2 but it just generates more warnings. I use these alongside of RVM.
I get "can't convert Symbol into Integer" when trying to boot a 2.3.x Rails app no matter what version of rubygems I run. I tried 1.5.7, 1.7.2, and 1.8.2.
$ script/server
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
path/.rvm/gems/ruby-1.9.2-p0/gems/rails-2.3.5/lib/rails/gem_dependency.rb:51:in `[]': can't convert Symbol into Integer (TypeError)
Any idea how I can get my system back in harmony?
As Dex and The Tin Man suggested in the comments, the solution was to run rails 2 on ruby 1.8.7 and rails 3 on ruby 1.9.2 using vrm. The warnings generated by rubygems 1.8.2 (now 1.8.3) are solved by running his suggest commands.