I'm trying to run scrapi with rails with this code:
require 'rubygems'
require 'scrapi'
require 'tidy'
scraper = Scraper.define do
process "title", :page_name => :text
result :page_name
end
uri = URI.parse("http://railscasts.com/episodes/173-screen-scraping-with-scrapi")
p scraper.scrape(uri)
but I get the following error:
DL is deprecated, please use Fiddle
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:5:in `<class:Tidybuf>': uninitialized constant DL::Importable (NameError)
from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:3:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy.rb:25:in `<module:Tidy>'
from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy.rb:21:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from scrapitest.rb:3:in `<main>'
has anybody got an idea why is that and what could I do to fix it?
Thank you.
Try http://github.com/libc/tidy_ffi instead. It seems tidy gem is not mantained anymore.
Related
I am trying to run a single test file: bundle exec rspec spec/models/user_spec.rb
But get following error:
An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error: config.include ::Rails::Controller::Testing::TemplateAssertions, type: :controller
NameError:
uninitialized constant Rails::Controller
Did you mean? ApiController
# ./spec/rails_helper.rb:149:in `block in <top (required)>'
# ./spec/rails_helper.rb:61:in `<top (required)>'
# ./spec/models/user_spec.rb:3:in `require'
# ./spec/models/user_spec.rb:3:in `<top (required)>'
No examples found.
Initially, I was getting following error:
An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error: module Shoulda::Matchers::ActiveModel
NameError:
uninitialized constant Shoulda
# ./spec/support/matchers/validate_kept_of_matcher.rb:4:in `<top (required)>'
# ./spec/rails_helper.rb:51:in `block in <top (required)>'
# ./spec/rails_helper.rb:51:in `each'
# ./spec/rails_helper.rb:51:in `<top (required)>'
# ./spec/models/user_spec.rb:3:in `require'
# ./spec/models/user_spec.rb:3:in `<top (required)>'
No examples found.
But then it fixed after I added following to the test file.
require "shoulda/matchers"
I am newbie in Ruby/Rails world, can someone please give a direction?
Rails::Controller::Testing::TemplateAssertions was removed in Rails 5.
You can re-add the depreciated functionality by installing the Rails controller testing gem. However the use of controller specs, assigns and template assertions is discouraged by both the RSpec and Rails teams and is not very future proof.
The community accepted solution is to write request specs and stop poking inside your controllers.
I have no idea what the problem is on this. I'm trying this in the rails console:
>> agent = Mechanize.new
NoMethodError: undefined method `user' for nil:NilClass
I added gem 'mechanize' and did a bundle install. I did require 'mechanize'. I also tried require 'nokogiri' below that, and every time I get the same error. I've tried 4 or 5 different ways to instantiate a new mechanize object and haven't been able to find one.
I searched my entire rails app for the string '.user' and couldn't find any. Not sure what the deal is here. Any ideas?
Thanks
EDIT
Full Stack trace
NoMethodError: undefined method `user' for nil:NilClass
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/net-http-persistent-2.9.2/lib/net/http/persistent.rb:866:in `proxy='
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:1189:in `set_proxy'
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/mechanize-2.7.2/lib/mechanize.rb:204:in `initialize'
from (irb):5:in `new'
from (irb):5
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands/console.rb:47:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands/console.rb:8:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands.rb:41:in `<top (required)>'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `require'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
You're not doing anything wrong: the version of mechanize that came out a few days ago is buggy. I solved that error just updating the gem (i.e., with bundle update mechanize).
Trying to learn the Ruby on Rails 3 Tutorial book, hung up right now: Section 2.2
example says:
rails generate scaffold User name:string email:string
I get:
C:\Sites\rails_projects\demo_app>rails generate scaffold User name:string email:
string
C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:
34:in `require': wrong number of arguments (0 for 1) (ArgumentError)
from C:/Sites/rails_projects/demo_app/Gemfile:4:in `evaluate'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/dsl.rb:7:in `instance_eval'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/dsl.rb:7:in `evaluate'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/definition.rb:17:in `build'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler.rb:138:in `definition'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler.rb:126:in `load'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler.rb:110:in `setup'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.21
/lib/bundler/setup.rb:7:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:57:in `require'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:57:in `rescue in require'
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:35:in `require'
from C:/Sites/rails_projects/demo_app/config/boot.rb:6:in `<top (require
d)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from script/rails:5:in `<main>'
Can someone please set me on the right track? Thanks!
i dont know if you are a new comer to rails 3 but if not and also if you are, i think DEVISE is a good gem to use .i have finished the book and i used devise for my authentication system. all you need do is install it manually from github so as to read its documentation and also more tutorials on ASCiiCast and railscast for videos (engaging with devise). it as a lot of methods that is used in the book e.g if signed_in, current_user, logged_in e.t.c and also destroy the user model before using DEVISE.
I would review your Gemfile to see that you have everything entered correctly.
HTH
I'm trying to install this as a plugin:
https://github.com/phatworx/rack_ip_restrictor
So I run:
$ rails plugin install git://github.com/phatworx/rack_ip_restrictor.git
This errors with:
/Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/railties-3.0.5/lib/rails/commands/plugin.rb:277:in `<top (required)>': Commands is not a module (TypeError)
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
from /Users/userme/.rvm/gems/ruby-1.9.2-p180#andyw/gems/railties-3.0.5/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Suggestions, ideas? Thanks
There's a solution out on GitHub - check the comments.
#acconrad is correct. the concrete solution is ( If you use rails 3.0.9- with rake 0.9.2, you should add include Rake::DSL to Rakefile just after require 'rake'.
Then add module Commands; end to script/rails just before require 'rails/commands', you will not get 'Commands is not a module (TypeError)' error message any more.) :
1.in Rakefile,
require File.expand_path('../config/application', __FILE__)
require 'rake'
# add this line of code
include Rake::DSL
2.in script/rails:
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
# add this line of code
module Commands; end
require 'rails/commands'
3.then run this command:
$ bundle exec rails plugin install git://github.com/sbecker/asset_packager.git
the plugin will be installed.
Have you tried with rails 3.0.10. It should work with 3.0.10 actually!
I'm trying to use the gravatar_image_tag RoR plug-in and it is giving me this error, when I start up the rails console or the rails server. What do I do to fix it?
/Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb:66: uninitialized constant ActionView::Helpers::AssetTagHelper::AssetPaths::Mutex (NameError)
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helper.rb:3:in `require'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers/asset_tag_helper.rb:3
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/helpers.rb:39
from /Library/Ruby/Gems/1.8/gems/actionpack-3.1.0.beta1/lib/action_view/base.rb:134
from /Library/Ruby/Gems/1.8/gems/gravatar_image_tag-1.0.0/lib/gravatar_image_tag.rb:97
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.13/lib/bundler.rb:120:in `require'
from /Users/pickhardt/projects/sample_app/config/application.rb:7
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:51
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48:in `tap'
from /Library/Ruby/Gems/1.8/gems/railties-3.1.0.beta1/lib/rails/commands.rb:48
from script/rails:6:in `require'
from script/rails:6
It's possible your plugin isn't compatible with your version of rails. Gravatar images aren't that hard to do with out a plugin. Here is a solution by Ryan Bates for Gravatars
application_helper.rb
def avatar_url(user)
if user.avatar_url.present?
user.avatar_url
else
default_url = "#{root_url}images/guest.png"
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=48&d=#{CGI.escape(default_url)}"
end
end
users/index.html.erb
<%= image_tag avatar_url(user) %>