Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the irbrc config file doesn't work for ruby 2 + rails 4

The irbrc config file works on the rails 3.2 + ruby 1.9

Today I checked out a project, using rails 4 + ruby 2,

and I found it didn't load the .irbrc file (I put the file under my home directory)

When I ran into irb or rails console

What's the problem?

irbrc file

require 'irb/completion'                                                 
require 'hirb' ; Hirb.enable                                             

ARGV.concat ["--readline", "--prompt-mode", "simple"]                    
IRB.conf[:SAVE_HISTORY] = 10000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history"                  

ActiveRecord::Base.logger.level = 1 # Avoid log in Rails console      
ActiveRecord::Base.logger = Logger.new STDOUT #顯示 SQL statements

ActiveRecord::Base.connection.tables
    def drop_tbl (tblname)
        ActiveRecord::Migration.drop_table(eval(":"+tblname))
    end
    def show_tbls
        tbls = ActiveRecord::Base.connection.tables
        tbls.each { |tbl|
            puts "#{tbl} #{tbl_name(tbl)}"
        }
    end
    def tbl_name(name)
        name.singularize.humanize.split().map{|x| x.capitalize}.join()
    end


    def cols (tblname)
        cols = eval("#{tblname}.column_names")
        ap(cols)
    end

Gemfile in the project

source 'https://rubygems.org'
ruby '2.0.0'

gem 'bootstrap-sass'
gem 'coffee-rails'
gem 'rails'
gem 'haml-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'jquery-rails'

group :development do
  gem 'sqlite3'
  gem 'pry'
  gem 'pry-nav'
  gem 'thin'
  gem "better_errors"
  gem "binding_of_caller"
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end
like image 904
newBike Avatar asked Dec 05 '25 04:12

newBike


1 Answers

I believe the irb config file doesn’t get loaded in rails console if the file is erroneous. Run ruby ~/.irbrc to make sure that it evaluates without complaint. Additionally, you can verify that your console is even sourcing your irbrc by running $LOAD_PATH.index{|s| s.include?('irbrc')} within your console.

like image 78
David Rivers Avatar answered Dec 08 '25 08:12

David Rivers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!