2010-12-15 42 views
2

我將在我的rails 3應用程序上使用可讀性gem。我不能使用它在應用程序內的github頁面http://github.com/sspinc/readability上建議,雖然它在ruby控制檯上工作正常。如何在Rails 3.0.x上使用可讀性gem?

在Ruby控制檯:

> require 'open-uri' 
=> true 
> require 'readability' 
=> true 
> doc = Nokogiri::HTML(open('http://google.com')) 
=> #<Nokogiri::HTML::Document:0x81345324 name="document" 
> doc.to_readable 
=> #<Nokogiri::XML::Element:0x813299a8 name="html" 
# (expected result without any error) 

在鐵軌上的控制檯:

> doc = Nokogiri::HTML(open('http://google.com')) 
=> #<Nokogiri::HTML::Document:0x81c2baec name="document" 
# (and so on.. expected result) 
> readable = doc.to_readable 
SyntaxError: /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:2: syntax error, unexpected '=' 
    if(typeof console !== 'undefined') { 
         ^
/Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:2: syntax error, unexpected '{', expecting kTHEN or ':' or '\n' or ';' 
/Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:5: syntax error, unexpected '}', expecting $end 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load' 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load' 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency' 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in' 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency' 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load' 
     from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/harmony-0.5.6/lib/harmony/page.rb:76:in `load' 

我證實,這不是一個JavaScript語法錯誤。根據主動支持錯誤判斷,它無法加載依賴關係,我懷疑Rails未能加載可讀性使用所需的gem(如harmony,johnson和envjs)來處理Ruby中的javascript和DOM。

所以我的猜測可能是錯誤的Gemfile中?這裏是我當前的Gemfile:

source 'http://rubygems.org' 

gem 'rails', '3.0.3' 
gem 'devise', '~> 1.1.5' 
gem 'haml', '3.0.24' 
gem 'simple_form' 
gem 'cancan' 
gem 'will_paginate', '~> 3.0.beta' 
gem 'feedzirra', :require => [ 'feedzirra' ] 
gem 'loofah', '1.0.0.beta.1' 
gem 'compass', '~> 0.10.4' 
gem 'meta_where', '~> 0.9' 
gem 'populator' 
gem 'simple-navigation' 
gem 'readability' 

我曾嘗試加入:需要可讀性選項來指定和諧,約翰遜和envjs;並reran'捆綁安裝'沒有任何錯誤,但我仍然有同樣的錯誤。

我也檢查過config/application.rb以要求Gemfile中的所有gem。用這條線

Bundler.require(:default, Rails.env) if defined?(Bundler) 

所以,回到這個問題,我怎樣才能在Rails 3.0.x上使用可讀性?我錯過了什麼?如果有問題,我正在使用MacOS 10.6.5。

謝謝

+1

你有沒有有沒有解決這個問題?我有這個寶石類似的問題。 – 2011-02-13 19:36:44

回答

1

我的Mac(Rails的3.x中,紅寶石1.9.2我與它裝載約翰遜寶石這是一個依賴麻煩。但是,紅寶石可讀性寶石的作品。

相關問題