Access my model from foreverb daemon - ruby-on-rails

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

Related

how to require a gem in rails test?

How do you test gem functionality? I'm trying to figure out why something isn't working the way the docs suggest, and set up my own version of these. Yet my test fail:
19: ...
18: ...
#...etc....
5: from /Users/me/code/project/test/shrine_test.rb:5:in `<top (required)>'
4: from /Users/me/code/project/test/shrine_test.rb:5:in `require'
3: from /Users/me/.rvm/gems/ruby-2.5.0/gems/lockbox-0.4.8/lib/lockbox.rb:20:in `<top (required)>'
2: from /Users/me/.rvm/gems/ruby-2.5.0/gems/lockbox-0.4.8/lib/lockbox.rb:20:in `require'
1: from /Users/me/.rvm/gems/ruby-2.5.0/gems/lockbox-0.4.8/lib/lockbox/railtie.rb:1:in `<top (required)>'
/Users/me/.rvm/gems/ruby-2.5.0/gems/lockbox-0.4.8/lib/lockbox/railtie.rb:2:in `<module:Lockbox>': uninitialized constant Rails::Railtie (NameError)
Did you mean? Rails
This is my test file, shrine_test.rb:
require "bundler/setup"
Bundler.setup
require "minitest/autorun"
require "minitest/pride"
require "lockbox" #this is the line 5 from above
$logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDOUT : nil)
require_relative "support/shrine"
require_relative "support/active_record"
Lockbox.master_key = SecureRandom.random_bytes(32)
class ShrineTest < Minitest::Test
#tests here
end
Assuming the gem in your Gemfile is in the default group (not in any group :environment do block), replace the Bundler.setup with
Bundler.require(:default)

"rails activestorage:update" errors out while upgrading to rails 6

I am performing an upgrade in rails version from 5.2.3 to 6.0.0 in our application and ended up with the following error when I run rails app:update and accept default changes.
Overwrite /Users/pk064816/solemnity/bin/setup? (enter "h" for help) [Ynaqdhm] y
force bin/setup
identical bin/yarn
rails active_storage:update
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/rule_monger-0.3.0/lib/rule_monger.rb:17: warning: already initialized constant HOST_PORT
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/netapp_oncommand_rest-0.2.1/lib/netapp_oncommand_rest.rb:21: warning: previous definition of HOST_PORT was here
rails aborted!
NameError: wrong constant name [[:error, ["detected unsupported rails version 6.0.0"], nil]]
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:52:in `const_get'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:52:in `load_framework_class'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:32:in `new_instance'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/new_relic/control/class_methods.rb:13:in `instance'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/newrelic_rpm-5.7.0.350/lib/newrelic_rpm.rb:41:in `block in <class:Railtie>'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `instance_exec'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `run'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:61:in `block in run_initializers'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/initializable.rb:60:in `run_initializers'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/application.rb:363:in `initialize!'
/Users/pk064816/ClosedStack/config/environment.rb:5:in `<main>'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/application.rb:339:in `require_environment!'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/application.rb:515:in `block in run_tasks_blocks'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/command.rb:48:in `invoke'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/Users/pk064816/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
bin/rails:8:in `<main>'
Tasks: TOP => active_storage:update => environment
(See full trace by running task with --trace)
After this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app.
I do not really make use of activestorage inside the application and any configs specific to activestorage are only the defaults obtained from rails 5.2.3.
Here's what I have in my bin/rails:
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
and in bin/setup:
#!/usr/bin/env ruby
require 'fileutils'
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
FileUtils.chdir APP_ROOT do
# This script is a way to setup or update your development environment automatically.
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies
# system('bin/yarn')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
and config/application.rb
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Solemnity
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Use Resque for our Active::Jobs
config.active_job.queue_adapter = :resque
# Add lib to autoload path
config.eager_load_paths << "#{Rails.root}/lib"
config.time_zone = 'Central Time (US & Canada)'
config.exceptions_app = self.routes
end
end
I tried to disable the use of activestorage, but that didn't really work! I am not entirely sure what's causing an error here and would really appreciate any help in working around this problem!

Testing code in a Rails engine with RSpec

I'm trying to do something seemingly simple but it's proven rather hard.
I want to write tests using RSpec for classes that I've put in the lib directory of a Rails Engine.
Here are exactly the steps I'm using:
rails plugin new mygem -T --mountable --full --dummy-path=spec/dummy
Then I cd mygem; vim mygem.gemspec
I add the following line to mygem.gemspec:
s.add_development_dependency "rspec-rails"
I run bundle install; rails generate rspec:install
Then I edit ~/mygem/lib/mygem/engine.rb adding the following:
module Mygem
class Engine < ::Rails::Engine
isolate_namespace Mygem
config.generators do |g|
g.test_framework :rspec
end
end
end
I create a very simple class in the lib directory, ~/mygem/lib/mygem/something.rb
and add the following:
module Mygem
class Something
def hi
"hi"
end
end
end
Create a test file ~/mygem/spec/something_spec.rb
then add the following:
require 'rails_helper'
describe Mygem::Something do
it 'says hi' do
s = Mygem::Something.new
expect(s.hi).to eq('hi')
end
end
And boom, I get the following output:
rspec
~/Documents/mygem/spec/rails_helper.rb:3:in `require': cannot load such file -- ~/Documents/mygem/config/environment (LoadError)
from ~/Documents/mygem/spec/rails_helper.rb:3:in `<top (required)>'
from ~/Documents/mygem/spec/something_spec.rb:1:in `require'
from ~/Documents/mygem/spec/something_spec.rb:1:in `<top (required)>'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `load' from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'
from ~/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.2/exe/rspec:4:in `<top (required)>'
from ~/.rvm/gems/ruby-2.2.2/bin/rspec:23:in `load'
from ~/.rvm/gems/ruby-2.2.2/bin/rspec:23:in `<main>'
from ~/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
from ~/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
Any tips as to what I may be doing incorrectly?
Thanks in advance!
It looks like your rails_helper is looking for an environment.rb file to load, which doesn't exist in a Rails engine. It does, however, exist in your dummy app, which is what RSpec is run against.
Try adding this into the top of your rails_helper file:
require File.expand_path("../dummy/config/environment.rb", __FILE__)
Finally got it working after the following steps (thanks ccai for the suggestion):
in rails_helper.rb:
# Comment this line:
# require File.expand_path('../../config/environment', __FILE__)
require File.expand_path("../dummy/config/environment.rb", __FILE__)
then in lib/mygem.rb
require "mygem/something"
Works!

unable to start rails console

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 !

How to install a plugin in rails 3, getting a Commands is not a module (TypeError)

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!

Resources