uninitialized constant (NameError) Ruby - ruby-on-rails

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
...

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)

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

uninitialized constant when running rspec test with concerns used in models

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?

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 !

Resources