Rubyful_soup works fine as an RB file but bugs in Rails

This is the code:

1 require ‘rubyful_soup’
2 require ‘open-uri’
3
4 url = “http://www.google.com/search?q=ruby
5 open(url) {
6 |page| page_content = page.read()
7 soup = BeautifulSoup.new(page_content)
8 result = soup.find_all(‘a’, :attrs => {‘class’ => ‘l’})
9 result.each { |tag| puts tag[‘href’] }
10 }

it works fine when i ran it: ruby rfs.rb
but when i wrap it with <%%> and try launching it in Rails, the
following occours:

TypeError in Articles#meca

Showing app/views/articles/meca.rhtml where line #2 raised:

superclass mismatch for class StackingParser

Extracted source (around line #2):

1: <%
2: require ‘rubyful_soup’
3: require ‘open-uri’
4:
5: url = “http://www.google.com/search?q=ruby

RAILS_ROOT: /app/sites/exe/ifeel/public/…/config/…
Application Trace | Framework Trace | Full Trace

/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/stparser.rb:11
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/tree.rb:16
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/site_ruby/1.8/rubygems.rb:182:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:181:inactivate’
/usr/lib64/site_ruby/1.8/rubygems.rb:167:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:166:inactivate’
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:26:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
#{RAILS_ROOT}/app/views/articles/meca.rhtml:2:in
`_run_rhtml_articles_meca’

/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/stparser.rb:11
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/tree.rb:16
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/site_ruby/1.8/rubygems.rb:182:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:181:inactivate’
/usr/lib64/site_ruby/1.8/rubygems.rb:167:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:166:inactivate’
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:26:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:314:in
compile_and_render_template' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:290:inrender_template’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:249:in
render_file' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:699:inrender_file’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:621:in
render_with_no_layout' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:243:inrender_without_benchmark’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
render' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:in
render' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:911:inperform_action_without_filters’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:368:in
perform_action_without_benchmark' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in
perform_action' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:381:inprocess_without_filters’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:377:in
process_without_session_management_support' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:117:inprocess’
#{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:38:in `dispatch’
/app/sites/exe/ifeel/public/dispatch.cgi:10

/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/stparser.rb:11
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/tree.rb:16
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/site_ruby/1.8/rubygems.rb:182:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:181:inactivate’
/usr/lib64/site_ruby/1.8/rubygems.rb:167:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:166:inactivate’
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:26:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
#{RAILS_ROOT}/app/views/articles/meca.rhtml:2:in
_run_rhtml_articles_meca' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:314:incompile_and_render_template’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:290:in
render_template' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:249:inrender_file’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:699:in
render_file' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:621:inrender_with_no_layout’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:243:in
render_without_benchmark' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:inrender’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:53:inrender’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:911:in
perform_action_without_filters' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:368:inperform_action_without_benchmark’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:82:inperform_action’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:381:in
process_without_filters' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:377:inprocess_without_session_management_support’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:117:in
process' #{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:38:indispatch’
/app/sites/exe/ifeel/public/dispatch.cgi:10

Request

Parameters: None

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}
Loaded suite /app/sites/exe/ifeel/public/dispatch.cgi Started Finished
in 0.000248 seconds. 0 tests, 0 assertions, 0 failures, 0 errors

Okay,

it was beacuse Mechanize (already installed) and Rubyful_soup both use
the StackingParser name for their classes (probably include some mutual
library for parsing). The simple short-term way to solve this enigma is
by ‘gem uninstall mechanize’.

:wink:

Dor K. wrote:

This is the code:

1 require ‘rubyful_soup’
2 require ‘open-uri’
3
4 url = “http://www.google.com/search?q=ruby
5 open(url) {
6 |page| page_content = page.read()
7 soup = BeautifulSoup.new(page_content)
8 result = soup.find_all(‘a’, :attrs => {‘class’ => ‘l’})
9 result.each { |tag| puts tag[‘href’] }
10 }

it works fine when i ran it: ruby rfs.rb
but when i wrap it with <%%> and try launching it in Rails, the
following occours:

TypeError in Articles#meca

Showing app/views/articles/meca.rhtml where line #2 raised:

superclass mismatch for class StackingParser

Extracted source (around line #2):

1: <%
2: require ‘rubyful_soup’
3: require ‘open-uri’
4:
5: url = “http://www.google.com/search?q=ruby

RAILS_ROOT: /app/sites/exe/ifeel/public/…/config/…
Application Trace | Framework Trace | Full Trace

/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/stparser.rb:11
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/ruby/gems/1.8/gems/htmltools-1.09/lib/html/tree.rb:16
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:21:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’
/usr/lib64/site_ruby/1.8/rubygems.rb:182:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:181:inactivate’
/usr/lib64/site_ruby/1.8/rubygems.rb:167:in activate' /usr/lib64/site_ruby/1.8/rubygems.rb:166:inactivate’
/usr/lib64/site_ruby/1.8/rubygems/custom_require.rb:26:in require' #{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:inrequire’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs