3
我試圖編輯我的〜/ .irbrc文件 並定義了show_tbls方法來獲取我擁有的表, 因爲命令很長,所以我試圖做一個函數以便於使用。我可以在Rails控制檯中定義別名
require 'hirb' ; Hirb.enable
require 'irb/completion'
def show_tbls
ActiveRecord::Base.connection.tables
end
當我跑了show_tbls 這表明誤差爲以下
1.9.3-p448 :001 > show_tbls()
NoMethodError: undefined method `show_tbls' for main:Object
from (irb):1
from /home/poc/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /home/poc/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /home/poc/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3-p448 :002 > show_tbls
NameError: undefined local variable or method `show_tbls' for main:Object
裏面你的方法對不起,我應該修改哪些文件? – newBike
這個文件〜/ .irbrc –
@SaidKaldybaev - 修改'.irbrc'的潛在含義是什麼?有沒有? – Tass