unable to start rails console - ruby-on-rails

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 !

Related

How to add iframe to sanitized tags in ruby on rails 4.2.6?

I am trying to add iframe to santized tags by using
config.action_view.sanitized_allowed_tags
I tried to find what tags are already allowed by using the console.
uraai#raiuorial:~/workspace/corse (master) $ heroku run rails c
Running rails c on ⬢ fa4... up, run.9396
Loading production environment (Rails 4.2.6)
irb(main):001:0> puts helper.sanitized_allowed_tags.to_a
NoMethodError: undefined method `sanitized_allowed_tags' for #<ActionView::Base:0x007f18ea91ea60>
from /app/vendor/bundle/ruby/2.3.0/gems/metamagic-3.1.7/lib/metamagic/view_helper.rb:30:in `method_missing'
from (irb):1
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from /app/bin/rails:8:in `require'
from /app/bin/rails:8:in `<main>'
irb(main):002:0>
Any idea how to add it without ignoring the other tags? Thanks
Please have a look on the next example:
module Tapp
class Application < Rails::Application
# In config/application.rb
config.action_view.sanitized_allowed_tags = ['strong', 'em', 'a', 'br', 'iframe']
# ...
end
My app called Tapp, I'm pretty sure you will have another name here ;)
Then in the console:
[retgoat#iMac-Roman ~/workspace/tapp]$ rc
Loading development environment (Rails 4.2.6)
[1] pry(main)> Tapp::Application.config.action_view[:sanitized_allowed_tags]
=> ["strong", "em", "a", "br", "iframe"]

my_zipcode_gem migration generators not working

I'm pretty sure that the problem is due to the fact that this gem looks to be 3-4 years old and rails has changed how we do migrations. But I'm not too familiar with gems/generators. I'm trying to follow the instructions to do the instructions listed here.
rails g my_zipcode_gem:models
rake db:migrate
rake zipcodes:update
However, when I do the first step I end up getting this:
/Users/thammond/.rvm/gems/ruby-2.1.1/gems/my_zipcode_gem-0.1.3/lib/generators/my_zipcode_gem/models_generator.rb:35:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError)
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/generators/migration.rb:63:in `migration_template'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/my_zipcode_gem-0.1.3/lib/generators/my_zipcode_gem/models_generator.rb:36:in `create_migration'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/generators.rb:157:in `invoke'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/generate.rb:11:in `<top (required)>'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:135:in `generate_or_destroy'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:51:in `generate'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/thammond/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Any idea what I need to do to get that gem working? It provides exactly what I'm looking for in my app.
Thanks!
Edit: Adding the generation code:
module MyZipcodeGem
class ModelsGenerator < Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def initialize(*args, &block)
super
end
def generate_models
# puts ">>> generate_zipcodes:"
end
def add_gems
add_gem "mocha", :group => :test
end
def create_models
template 'zipcode_model.rb', "app/models/zipcode.rb"
template 'county_model.rb', "app/models/county.rb"
template 'state_model.rb', "app/models/state.rb"
end
# Implement the required interface for Rails::Generators::Migration.
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
Time.now.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
end
def create_migration
migration_template 'migration.rb', "db/migrate/create_my_zipcode_gem_models.rb"
end
def create_rakefile
template 'zipcodes.rake', "lib/tasks/zipcodes.rake"
end
end
end
# /Users/cblackburn/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/rails/generators/active_record/
It looks like it is calling the migration using parameters that are no longer expected. You have two options:
1) fork the code, update it to use rails 4 conventions, and create a pull request on github. Assuming the owner is still active they will bring your code into the master and republish the gem. You would have help support the community and feel good about it in the process. There are plenty on here like myself who can help you with this.
2) Find another gem to do what you want, such as http://www.rubygeocoder.com/ which I've used several times and is awesome at doing location/zipcode problems

Override Ruby class method; can't resolve namespace

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

Access my model from foreverb daemon

I have the following code on a foreverb daemon to access my Availability model. but I always get the following error:
uninitialized constant Availability
Here is my daemon:
#!/usr/bin/ruby
require 'rubygems' unless defined?(Gem)
require 'forever'
require 'mongoid'
Forever.run do
every 10.seconds do
#classes = Availability.where(:availability_date.gt => Time.now.utc + 1.hours).to_a
puts #classes.count
end
end
Thanks for your help.
Note: I'm using rails3 and mongoid.
UPDATED CODE
#!/usr/bin/env ruby
require 'rubygems' unless defined?(Gem)
require 'forever'
require 'mongoid'
require File.expand_path('../config/environment', __FILE__)
Forever.run do
every 10.seconds do
#classes = Availability.where(:availability_date.gt => Time.now.utc + 1.hours).to_a
puts #classes.count
end
end
Now I'm getting the following error:
user/classes_notification.rb; tail -f -n 150 user/sample.log;
/Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require': cannot load such file -- /Users/jeanosorio/repos/blabloo/script/user/config/environment (LoadError)
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from user/classes_notification.rb:6:in `<main>'
UPDATE
UPDATE PATH
#!/usr/bin/env ruby
require 'rubygems' unless defined?(Gem)
require 'forever'
require 'mongoid'
# Load Rails
#ENV['RAILS_ENV'] = ARGV[0] || 'development'
require File.expand_path('../../../config/environment', __FILE__)
Forever.run do
every 10.seconds do
#classes = Availability.where(:availability_date.gt => Time.now.utc + 1.hours).to_a
puts #classes.count
end
end
Now I'm getting this eror:
script/user/classes_notification.rb; tail -f -n 150 script/user/sample.log;
WARN: Unresolved specs during Gem::Specification.reset:
thor (>= 0.15.0)
tzinfo (~> 0.3.22)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/jeanosorio/.rvm/gems/ruby-1.9.3-p484#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:34:in `block in setup': You have already activated multi_json 1.10.1, but your Gemfile requires multi_json 1.8.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
from /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p484#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:19:in `setup'
from /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p484#global/gems/bundler-1.5.2/lib/bundler.rb:119:in `setup'
from /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p484#global/gems/bundler-1.5.2/lib/bundler/setup.rb:7:in `<top (required)>'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:135:in `require'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:144:in `require'
from /Users/jeanosorio/repos/blabloo/config/boot.rb:6:in `<top (required)>'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from /Users/jeanosorio/repos/blabloo/config/application.rb:1:in `<top (required)>'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from /Users/jeanosorio/repos/blabloo/config/environment.rb:2:in `<top (required)>'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from /Users/jeanosorio/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:126:in `require'
from script/user/classes_notification.rb:9:in `<main>'
This is very easy load Rails env just add to top of your script:
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __FILE__)
Worked this simple 3 lines script in Rails.root dir.
Another examples

How to run ScrAPI with Ruby?

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.

Resources