I want to override this method, abbreviated here.
class Redis
module Connection
class Ruby
include Redis::Connection::CommandHelper
def self.connect(config)
if config[:scheme] == "unix"
sock = UNIXSocket.connect(config[:path], config[:timeout])
else
sock = TCPSocket.connect(config[:host], config[:port], config[:timeout])
if config[:scheme] == "rediss" or config[:use_ssl]
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.ca_file = config[:ssl_ca_file]
ssl_context.key = config[:ssl_key]
ssl_context.cert = config[:ssl_cert]
ssl_context.verify_mode = config[:ssl_verify_mode]
ssl_client = OpenSSL::SSL::SSLSocket.new sock, ssl_context
ssl_client.connect
sock = ssl_client
end
end
instance = new(sock)
instance.timeout = config[:timeout]
instance.set_tcp_keepalive config[:tcp_keepalive]
instance
end
end
end
end
So I've created a RubyGem, that has a runtime dependency on 'redis'. In the gem's lib folder, I have a file with
begin
require "openssl"
rescue LoadError
#ignore the error, ssl support will not work
end
Redis::Connection::Ruby.class_eval do
def self.connect(config)
if config[:scheme] == "unix"
sock = UNIXSocket.connect(config[:path], config[:timeout])
else
sock = TCPSocket.connect(config[:host], config[:port], config[:timeout])
if config[:scheme] == "rediss" or config[:use_ssl]
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.ca_file = config[:ssl_ca_file]
ssl_context.key = config[:ssl_key]
ssl_context.cert = config[:ssl_cert]
ssl_context.verify_mode = config[:ssl_verify_mode]
ssl_client = OpenSSL::SSL::SSLSocket.new sock, ssl_context
ssl_client.connect
sock = ssl_client
end
end
instance = new(sock)
instance.timeout = config[:timeout]
instance.set_tcp_keepalive config[:tcp_keepalive]
instance
end
end
Here's the error I get:
/vagrant/misinformed/redis-rb-ssl/lib/redis/connection/ruby.rb:7:in `<top (required)>': uninitialized constant Redis::Connection::Ruby (NameError)
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis/connection.rb:9:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis/connection.rb:9:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:2631:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:2631:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:72:in `each'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:72:in `block in require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:61:in `each'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:61:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler.rb:134:in `require'
from /vagrant/dragondoor/config/application.rb:7:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:146:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:146:in `require_application_and_environment!'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
How can I override that method? My guess is that I either have the namespacing wrong or I need to require something, but I haven't been able to get anything to work.
UPDATED:
Per a deleted comment, I also tried
begin
require "openssl"
rescue LoadError
#ignore the error, ssl support will not work
end
class Redis
module Connection
Ruby.class_evel do
def self.connect(config)
if config[:scheme] == "unix"
sock = UNIXSocket.connect(config[:path], config[:timeout])
else
sock = TCPSocket.connect(config[:host], config[:port], config[:timeout])
if config[:scheme] == "rediss" or config[:use_ssl]
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.ca_file = config[:ssl_ca_file]
ssl_context.key = config[:ssl_key]
ssl_context.cert = config[:ssl_cert]
ssl_context.verify_mode = config[:ssl_verify_mode]
ssl_client = OpenSSL::SSL::SSLSocket.new sock, ssl_context
ssl_client.connect
sock = ssl_client
end
end
instance = new(sock)
instance.timeout = config[:timeout]
instance.set_tcp_keepalive config[:tcp_keepalive]
instance
end
end
end
end
which seems to have gotten me a little farther, but still getting an error message
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:39: warning: Insecure world writable dir /vagrant/dragondoor in PATH, mode 040777
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler.rb:302: warning: Insecure world writable dir /vagrant/dragondoor in PATH, mode 040777
/vagrant/misinformed/redis-rb-ssl/lib/redis/connection/ruby.rb:9:in `<module:Connection>': uninitialized constant Redis::Connection::Ruby (NameError)
from /vagrant/misinformed/redis-rb-ssl/lib/redis/connection/ruby.rb:8:in `<class:Redis>'
from /vagrant/misinformed/redis-rb-ssl/lib/redis/connection/ruby.rb:7:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis/connection.rb:9:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis/connection.rb:9:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:2631:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.2.1/lib/redis.rb:2631:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:72:in `each'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:72:in `block in require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:61:in `each'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:61:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler.rb:134:in `require'
from /vagrant/dragondoor/config/application.rb:7:in `<top (required)>'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:146:in `require'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:146:in `require_application_and_environment!'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.1.9/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
Try adding require 'redis' to the file where you monkey patch the method:
require 'redis'
class Redis
module Connection
class Ruby
def self.connect(config)
puts 'the method is overriden'
end
end
end
end
Related
I am working on Ruby on Rails application which requires to access an External API via GET requests. The request needs to send some parameters with request. I have used Activeresource gem for accessing API. The API request is working fine in Postman and giving expected records but gives me a 400 error from Rails application.
Following is the code
class PayRunEmploymentHeroBase < ActiveResource::Base
self.site = "https://api.yourpayroll.com.au"
self.user = ENV['EMPLOYMENT_HERO_USERNAME']
self.element_name = ""
self.include_format_in_path = false
self.prefix = "/api/v2/business/:business_id/payrun?$filter=DateFinalised gt datetime':finalised_date'"
end
I am pasting here the details of 400 error while accessing the link from Rails app.
Reloading...
=> true
2.3.0 :006 > PayRunEmploymentHeroBase.find(:all, params: {:business_id => business_id, :finalised_date => finalised_date})
##############################################INFO##############################################
{
"method": "get",
"request_uri": "https://api.yourpayroll.com.au:443/api/v2/business/48058/payrun?$filter=DateFinalised gt datetime'2017-11-16'",
"http_status": "400",
"http_message": "Bad Request"
}
##############################################INFO##############################################
ActiveResource::BadRequest: Failed. Response code = 400. Response message = Bad Request.
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:141:in `handle_response'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:126:in `request'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `block in get'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:220:in `with_auth'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `get'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:1073:in `find_every'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:974:in `find'
from (irb):6
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/console.rb:65:in `start'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<main>'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `block in require'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `require'
from /Users/bebble1/work/awe/bin/rails:9:in `<main>'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `load'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `load'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `load'
from /Users/bebble1/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/bebble1/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
I have also attached a picture here of the outcome from Rails app
It seems like you are not authenticating with Rails app. And I am sure you have set authentication username/password in Postman.
Set self.password = "password" (use your own password) to PayRunEmploymentHeroBase and it will work.
Update:
It's actually your url is not encoded, do this and it will solve the issue:
self.prefix = "/api/v2/business/:business_id/payrun?$filter=" + URI::encode("DateFinalised gt datetime':finalised_date'")
I am fairly new to ruby and trying to write a gem file but the following error occurs.I have updated bundler and the relevant gems as was suggested in other posts.
Developing with
ubuntu 18.04LTS
ruby 2.5.1p57
gem 3.1.2
Traceback (most recent call last):
15: from /usr/local/bin/vcdm:23:in `<main>'
14: from /usr/local/bin/vcdm:23:in `load'
13: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/bin/vcdm:4:in `<top (required)>'
12: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
11: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
10: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm.rb:2:in `<top (required)>'
9: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
8: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
7: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/command.rb:1:in `<top (required)>'
6: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/command.rb:4:in `<module:Vcdm>'
5: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/command.rb:4:in `glob'
4: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
3: from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
2: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/commands/hostfile.rb:4:in `<top (required)>'
1: from /var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/commands/hostfile.rb:5:in `<module:Vcdm>'
/var/lib/gems/2.5.0/gems/vcdm-0.1.2/lib/vcdm/commands/hostfile.rb:14:in `<class:HostfileCommand>': uninitialized constant Vcdm::HostfileCommand::CommandOption (NameError)
These are my code what I am tring to execute
command_option.rb
module Vcdm
class CommandOption
attr_reader :name, :type, :description
def initialize(name, type, description)
#name = name
#type = type
#description = description
end
end
end
hostfile.rb
require 'vcdm/command_interface'
module Vcdm
class HostfileCommand
as = CommandOption.new("--path STRING", String, "custom hosts path")
IS_PUBLIC_COMMAND = true
SYNTAX = 'vcdm hostfile'
SUMMARY = 'adds the ingress url to the users hostfile'
DESCRIPTION = ""
EXAMPLE = "vcdm hostfile --path=/mnt/c/Windows/System32/drivers/etc/hosts"
EXAMPLE_DESCRIPTION = ""
implements CommandInterface
end
end
command_interface.rb
require 'class_interface'
class CommandInterface
IS_PUBLIC_COMMAND = true | false
SYNTAX = String
SUMMARY = String
DESCRIPTION = String
EXAMPLE = String
EXAMPLE_DESCRIPTION = String
OPTIONS = Array
def initialize
end
def execute(args, options)
end
end
Is there anything wrong?
It feels to me like you are missing a
require 'vcdm/command_option'
in your hostfile.rb. Just add that line to the top of that file.
try putting this in 'config/application.rb'
config.eager_load_paths << "#{Rails.root}/lib"
and then in 'hostfile.rb'
require 'vcdm/command_interface'
module Vcdm
include CommandOption
class HostfileCommand
...
When I run rspec spec/models/football_match_spec.rb I get an uninitialized constant error:
/Users/jamessmith/project/app/models/football_match.rb:3:in `<class:FootballMatch>': uninitialized constant FootballMatch::Type1Fixture (NameError)
from /Users/jamessmith/project/app/models/football_match.rb:1:in `<top (required)>'
from /Users/jamessmith/project/spec/models/football_match_spec.rb:3:in `<top (required)>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in `load'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in `each'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:97:in `setup'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:85:in `run'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:70:in `run'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/exe/rspec:4:in `<top (required)>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load' from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Type1Fixture concern:
module Type1Fixture
extend ActiveSupport::Concern
def competitors
[competitor_1, competitor_2]
end
def competitor_1_score
[fhhts || 0, shhts || 0, ethts || 0].reduce(:+)
end
def competitor_2_score
[fhats || 0, shats || 0, etats || 0].reduce(:+)
end
def name_with_scores
if [Fixture::IN_PROGRESS_STATUS, Fixture::COMPLETED_STATUS].include?(status)
"#{competitor_1.name} #{home_team_score} - #{away_team_score} #{competitor_2.name}"
else
"#{competitor_1.name} vs #{competitor_2.name}"
end
end
end
Edited FootballMatch model:
class FootballMatch < Fixture
include Mongoid::Document
include Type1Fixture
end
I've added app/models/concerns to the config.autoload_paths array in environments/test.rb.
This can be caused by not having the correct file name. For Type1Fixture, the file containing the class should be called app/models/concerns/type1_fixture.rb. Is this the case?
I'm new to ruby and tried following what this tutorial (http://www.youtube.com/watch?v=-GQmC-8k09c) said but I'm having problem with the console. I'm running a linuxmint 17 and this are my specs
Ruby version 2.1.2-p95 (x86_64-linux)
RubyGems version 2.2.2
Rack version 1.5
Rails version 4.1.1
JavaScript Runtime Node.js (V8)
I have tried :
spring stop
bundle install
whenever I run rails c this happens:
Loading development environment (Rails 4.1.1)
load error: /home/hanwai/.rvm/rubies/ruby-2.1.2/.irbrc
NoMethodError: undefined method `split' for nil:NilClass
/home/hanwai/.rvm/scripts/irbrc.rb:45:in `<top (required)>'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
/home/hanwai/.rvm/rubies/ruby-2.1.2/.irbrc:11:in `<top (required)>'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/home/hanwai/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/init.rb:236:in `run_config'
/home/hanwai/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/init.rb:19:in `setup'
/home/hanwai/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:380:in `start'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
/home/hanwai/rails/blog/bin/rails:8:in `<top (required)>'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/hanwai/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/home/hanwai/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
irb(main):001:0>
this is my irbrc.rb file
# This is the common irbrc file used by all rvm ruby installations.
# This file will be overriden every time you update rvm.
# Turn on completion.
begin
require "readline"
require "irb/completion" rescue nil
# Turn on history saving.
# require "irb/ext/save-history"
# IRB.conf[:HISTORY_FILE] = File.join(ENV["HOME"], ".irb-history")
# Use an alternate way to on history saving until save-history is fixed.
#
# bug: http://redmine.ruby-lang.org/issues/show/1556
# patch: http://pastie.org/513500
#
# This technique was adopted from /etc/irbrc on OS X.
histfile = File.expand_path(".irb-history", ENV["HOME"])
if File.exist?(histfile)
lines = IO.readlines(histfile).collect { |line| line.chomp }
Readline::HISTORY.push(*lines)
end
Kernel::at_exit do
maxhistsize = 100
histfile = File::expand_path(".irb-history", ENV["HOME"])
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
lines = lines[-maxhistsize, maxhistsize] if lines.compact.length > maxhistsize
File::open(histfile, "w+") { |io| io.puts lines.join("\n") }
end
rescue LoadError
puts "Readline was unable to be required, if you need completion or history install readline then reinstall the ruby.\nYou may follow 'rvm notes' for dependencies and/or read the docs page https://rvm.io/packages/readline/ . Be sure you 'rvm remove X ; rvm install X' to re-compile your ruby with readline support after obtaining the readline libraries."
end
# Calculate the ruby string.
rvm_ruby_string = ENV["rvm_ruby_string"] ||
(
ENV['GEM_HOME'] &&
path = ( File.realpath(ENV['GEM_HOME'].to_s) rescue nil ) &&
( path = $1 if path =~ /(.+)\/$/ ; true ) &&
path.split(/\//).last.split(/#/).first
) ||
("#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" rescue nil) ||
(RUBY_DESCRIPTION.split(" ")[1].sub('p', '-p') rescue nil ) ||
(`ruby -v` || '').split(" ")[1].sub('p', '-p')
# cut ruby- ... everyone knows it's ruby
rvm_ruby_string = $1 if rvm_ruby_string =~ /^ruby[- ](.*)/
# Set up the prompt to be RVM specific.
#prompt = {
:PROMPT_I => "#{rvm_ruby_string} :%03n > ", # default prompt
:PROMPT_S => "#{rvm_ruby_string} :%03n%l> ", # known continuation
:PROMPT_C => "#{rvm_ruby_string} :%03n > ",
:PROMPT_N => "#{rvm_ruby_string} :%03n?> ", # unknown continuation
:RETURN => " => %s \n",
:AUTO_INDENT => true
}
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RVM] = #prompt
IRB.conf[:PROMPT_MODE] = :RVM if IRB.conf[:PROMPT_MODE] == :DEFAULT
# Load the user's irbrc file, if possible.
# Report any errors that occur.
begin
load File.join(ENV["HOME"], ".irbrc") if File.exist?("#{ENV["HOME"]}/.irbrc")
rescue LoadError => load_error
puts load_error
rescue => exception
puts "Error : 'load #{ENV["HOME"]}/.irbrc' : #{exception.message}"
end
any advices?
You can try with the command irb (which is a Ruby command-line interpreter too) instead of rails c, it can be enough.
If not, see this solution which is near your problem.
Hope this help !
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.