How can I use readability gem on Rails 3.0.x? - ruby

I'm going to use readability gem on my rails 3 app. I can't use it as advised on the github page http://github.com/sspinc/readability inside the app although it works fine on ruby console.
On the ruby console:
> 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)
On the rails console:
> 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'
I verified that it is not a javascript syntax error. Judging by the active support error, it failed loading the dependencies, I suspect that Rails has failed to load the required gems that readability use (like harmony, johnson and envjs) to handle javascript and DOM in Ruby.
So my guess was may be somthing wrong in the Gemfile? Here's my current 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'
I have tried adding :require option in readability to specify harmony, johnson and envjs; and reran 'bundle install' without any error, but I still have the same error.
I have also checked the config/application.rb to require all the gems in the Gemfile. with this line
Bundler.require(:default, Rails.env) if defined?(Bundler)
So, back to the question, how can I use readability on Rails 3.0.x? Did I miss something? I'm on MacOS 10.6.5 if that matters.
Thank you

On my Mac (Rails 3.x, Ruby 1.9.2 I had trouble with it loading the johnson gem which is a dependency . However, ruby-readability gem works.

Related

Heroku assets are not loading and seems assets are out of date

I am having an issue where images on my Heroku production site are not being found. I have tracked it down to the digest being different in the file system from what it is looking for in the app. For example, in the logs I see the following errors:
app[web.1]: Started GET "/assets/nfl_teams/nfcn/chi-6317d0375db3876a5057f2da59bab1dc.jpeg" for 24.55.52.101 at 2016-09-08 23:10:18 +0000
app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/nfl_teams/nfcn/chi-6317d0375db3876a5057f2da59bab1dc.jpeg"):
app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:38:in `call_app'
And when I go to the Heroku console and look up the asset using asset_path() I get the following:
$ heroku run rails console
Running rails console on ⬢ fbpm... up, run.7463
Loading production environment (Rails 4.2.5)
irb(main):001:0> puts helper.asset_path("nfl_teams/nfcn/chi.jpg")
/assets/nfl_teams/nfcn/chi-93d8c8c53ac98c60f7f3fee1fade067dfa9489b24b8fa4bb9fedd4b12da129de.jpg
=> nil
irb(main):002:0>
and finally looking at the heroku bash and checking the file in the directory I get:
$ heroku run bash
Running bash on ⬢ fbpm... up, run.7321
cd public~ $ cd public/assets/nfl_teams/nfcn
~/public/assets/nfl_teams/nfcn $ ls chi*.jpg
chi-93d8c8c53ac98c60f7f3fee1fade067dfa9489b24b8fa4bb9fedd4b12da129de.jpg
~/public/assets/nfl_teams/nfcn $
So, in the console looking at the asset path I get the following file:
/assets/nfl_teams/nfcn/chi-93d8c8c53ac98c60f7f3fee1fade067dfa9489b24b8fa4bb9fedd4b12da129de.jpg
And I get the same file when I look in the directory structure. Yet for some reason the application is looking for this file:
/assets/nfl_teams/nfcn/chi-6317d0375db3876a5057f2da59bab1dc.jpeg
Which doesn't exist and throws a routing error.
Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.2.4'
#ruby-gemset=Rails_fb
gem 'rails','4.2.5'
gem 'bcrypt', '3.1.11'
gem 'annotate'
gem 'faker', '1.6.3'
gem 'select2-rails'
gem 'simple_form', '3.1.1'
gem 'cocoon'
#
# Bootstrap support gems
#
gem 'bootstrap-sass'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'font-awesome-sass', '4.6.2'
gem 'font-awesome-rails'
gem 'sass-rails', '~> 5.0.4'
#gem 'select2-sass-bootstrap-rails'
# The following Gem is used to parse the NFL page for schedules to build
# a season.
gem 'nokogiri'
# Database. Using the same database for production/development
gem 'pg'
group :development, :test do
gem 'rspec-rails', '~>3.0'
gem 'factory_girl_rails', '4.7.0'
gem 'capybara', '2.7.1'
gem 'database_cleaner'
gem 'guard-rspec', '~> 4.2'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess', '0.5.8'
gem 'letter_opener_web', '~>1.2.0'
end
group :test do
gem 'pry'
gem 'selenium-webdriver', '2.53.0'
gem 'libnotify', '0.9.1'
end
gem 'uglifier', '2.7.2'
gem 'coffee-rails', '4.1.1'
gem 'jquery-rails', '3.1.4'
gem 'jquery-turbolinks', '2.1.0'
gem 'turbolinks', '2.5.3'
gem 'jbuilder', '2.4.1'
group :doc do
gem 'sdoc', '0.4.1', require: false
end
group :production do
gem 'rails_12factor'
end
# To use debugger
# gem 'debugger'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
And here is the code I'm using to access the images in my views(I've tried it both with and without the asset_path() call):
<%= image_tag(asset_path(team.imagePath), size: "40") %>
Can anyone tell me why the app is looking for the wrong file? Obviously there is some disconnect in the asset pipeline but I can't figure where?
And this problem started after I upgraded from Ruby 2.0.0 to Ruby 2.2.4 which caused me to update a number of my Gems.
Hopefully this helps. In order to force a new precompile of assets on Heroku in Rails 4 you need to do the following:
rake assets:clobber
Rake assets:precompile
Then git commit/push to master and push to Heroku and it should do a new precompile that hopefully will sync up the asset pipeline. Don't use rake assets:clean as it doesn't force a new compile.

rake db:migrate rake aborted! unable to determine name from existing gemspec

I am trying to rake db:migrate. I cloned a repository and tried to rake db:migrate, but get this error :
rake aborted!
Unable to determine name from existing gemspec. Use :name => 'gemname' in #inst
ll_tasks to manually set it. C:/Users/Dila/Documents/emo_project/Rakefile:6:in `<top (required)>'
In my Rakefile line 6, I have this :
require "bundler/gem_tasks"
This is what I got, when I trace it :
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_helper.rb:30:i
n `initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_helper.rb:14:i
n `new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_helper.rb:14:i
n `install_tasks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.1/lib/bundler/gem_tasks.rb:2:in
`<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:251:in `require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:251:in `block in require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:236:in `load_dependency'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/depen
dencies.rb:251:in `require'
C:/Users/Dila/Documents/emo_project/Rakefile:6:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `l
oad'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `l
oad_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:589:in `
raw_load_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:89:in `b
lock in load_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `
standard_exception_handling'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:88:in `l
oad_rakefile'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:72:in `b
lock in run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `
standard_exception_handling'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `r
un'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>
'
C:/Ruby193/bin/rake:23:in `load'
C:/Ruby193/bin/rake:23:in `<main>'
I have no idea what is went wrong, because yesterday I was working in my office and everything was ok. I just wanna try to clone the repository in my laptop, but it doesn't work.
my gemfile :
source 'https://rubygems.org'
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
group :production do
gem 'pg', '0.12.2'
end
gem 'magic_encoding'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'activeadmin'
gem "bcrypt-ruby", :require => "bcrypt"
# to copy to clipboard
gem 'zeroclipboard-rails'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
#gem 'therubyracer'
gem 'uglifier', '>= 1.0.4'
gem 'sass-rails', '~> 3.2'
gem 'bootstrap-sass', '~> 2.3.1.0'
gem 'closure-compiler'
end
gem 'jquery-rails'
I see in your gemfile that you set postgresql as your production database, however you also set sqlite to run on production, test, and development.
group :production do
gem 'pg', '0.12.2'
end
# Skip some lines to here
gem 'sqlite3'
I would make sure your database is uniform across the test, development, and production servers. I would remove sqlite3 and simply have
group :production do
gem 'pg', '0.12.2'
end
replaced with
gem 'pg', '0.12.2'
That way, postgresql will run on all platforms. Or if your database.yml is connected to sqlite, then get rid of postgresql and keep the sqlite gem in your gemfile.

rake aborted! undefined method `setup' for ActiveAdmin:Module

I have installed active admin on my development machine and it works fine.
But when i run heroku run rake db:migrate it gives me following error
rake aborted! undefined method `setup' for ActiveAdmin:Module
here is my gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'pg'
gem 'haml'
gem 'haml-rails'
gem 'sorcery'#, "~> 0.7.12"
gem 'jquery-rails'
gem 'localeapp'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem "activeadmin", :git => "git://github.com/gregbell/active_admin.git"
gem 'sass-rails'#, '~> 3.2.5'
gem 'coffee-rails'#, '~> 3.2.2'
gem 'twitter-bootstrap-rails'
gem 'uglifier'
end
group :production do
gem 'thin'
end
gem "activeadmin", :git => "git://github.com/gregbell/active_admin.git"
Don't declare active admin under any group.
Atleast it wont work in production environment.
For the record, I wanted to try activeadmin-cms 0.1.0 and I had the same problem.
The gem activeadmin-cms is not compatible with activeadmin 0.6.0 (I have not tested other version of activeadmin)

Rails - can't run autotest

After my upgrade to Rails 3.1.3 and Ruby 1.9.3 (via RVM) i can't normally run autotest. I don't know what has happened, but when i print:
$ autotest
It shows strange error
loading autotest/rails_rspec2
/Users/serg/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- autotest/fsevent (LoadError)
from /Users/serg/.rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/serg/rails_projects_terminal/sample_app/.autotest:2:in `<top (required)>'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/lib/autotest.rb:315:in `load'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/lib/autotest.rb:315:in `block in initialize'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/lib/autotest.rb:314:in `each'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/lib/autotest.rb:314:in `initialize'
from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.8.0/lib/autotest/rspec2.rb:13:in `initialize'
from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-rails-2.8.0/lib/autotest/rails_rspec2.rb:31:in `initialize'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/lib/autotest.rb:244:in `new'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/lib/autotest.rb:244:in `run'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/gems/ZenTest-4.6.2/bin/autotest:6:in `<top (required)>'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/bin/autotest:19:in `load'
from /Users/serg/.rvm/gems/ruby-1.9.3-head#global/bin/autotest:19:in `<main>'
But when i try:
bundle exec autotest
It works. How can i fix it?
My gemfile:
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'gravatar_image_tag'
gem 'will_paginate'
gem 'rack'
gem 'texticle', "2.0", :require => 'texticle/rails'
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
end
gem 'jquery-rails'
group :development do
gem 'rspec-rails'
gem 'therubyracer-heroku'
gem 'pg'
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
gem 'faker'
end
group :test do
gem 'rspec-rails'
gem 'webrat'
gem 'spork'
gem 'autotest'
gem 'autotest-rails-pure'
gem 'autotest-fsevent'
gem 'autotest-growl'
gem 'factory_girl_rails'
end
group :production do
gem 'pg'
end
I had that issue as well, and to fix it I had to do what you did :
$ gem update ZenTest
$ gem cleanup ZenTest
$ gem install autotest-fsevent
But I also had to add 'autotest-growl' and 'autotest-fsevent' to my gemfile, which now looks like this:
group :development do
gem 'sqlite3'
gem 'rspec-rails'
gem 'autotest'
gem 'ZenTest'
gem 'autotest-growl'
gem 'autotest-fsevent'
end
Then
$ Bundle install
And now
$ autotest
works just fine :)
I solved it. I found this page: http://www.viget.com/extend/how-why-to-run-autotest-on-your-mac/
and then i printed in the Terminal:
$ gem update ZenTest
$ gem cleanup ZenTest
$ gem install autotest-fsevent
After that autotest started to work fine.

Ruby Bundler Permission issue

So, I'm positive I once did a sudo bundle install out of desperation, which I now understand is a no-no. But now, when i try to run bundle install, I get the following error:
Installing culerity (0.2.12) /Library/Ruby/Site/1.8/rubygems/installer.rb:294:in `generate_bin': You don't have write permissions into the /Library/Ruby/Gems/1.8/bin directory. (Gem::FilePermissionError)
from /Library/Ruby/Site/1.8/rubygems/installer.rb:196:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/source.rb:100:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/installer.rb:55:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/installer.rb:44:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/installer.rb:8:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/cli.rb:217:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/vendor/thor/task.rb:22:in `send'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.0.rc.6/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19
I've tried removeing everything in ~/.bundle ~/.gem .bundle Gemfile.lock as well as any reference to culerity or capybara in /Library/Ruby (OSX 10.6). I also checked to make sure permissions were set correctly (not root) on all my files in this project. I also cleared the gem cache.
My Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.0.rc2'
# Bundle edge Rails instead:
#gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end
gem 'haml', '3.0.15'
gem 'mogli', '0.0.13' #, :path => "~/Sites/mogli"
gem 'facebooker2', '0.0.4'
gem 'geokit'
gem 'acts_as_restful_list'
gem 'hoptoad_notifier'
group :development, :test do
gem "rspec-rails", '2.0.0.beta.19'
gem 'factory_girl_rails'
gem 'capybara', '0.3.9'
gem 'database_cleaner'
gem 'cucumber-rails', '0.3.2'
gem 'cucumber', '0.8.5'
gem 'spork'
gem 'launchy' # So you can do Then show me the page
end
Also, I have rvm on my system, but I'm using the system ruby for this project.
Any ideas on what's causing the permission issue? Surely, I'm not stuck using sudo bundle install.
Thanks.
It look like you are using the system's ruby. You have a few options:
use sudo to install your bundle system wide. it could be a problem with conflicting gems from different applications.
use bundle install --path bundle_dir, which is going to install the gems in bundle_dir
use rvm (http://rvm.beginrescueend.com), this program will allow you to use different ruby versions, and different gem sets.
Try to touch a file in the particular path. I guess OS X is protecting these directories a bit more than just the normal way? I think OS X supports ACL's with their filesystem, maybe you have to look there?
maybe try using chmod on everything, but looks like you'll need to run it as sudo...not sure why that's not an option...

Resources