-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrailsrc
36 lines (30 loc) · 906 Bytes
/
railsrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#http://rbjl.net/49-railsrc-rails-console-snippets
ActiveRecord::Base.logger = Logger.new STDOUT
ActiveRecord::Base.clear_reloadable_connections!
ActionController::Base.logger = Logger.new STDOUT
# console custom prompt
app_name = Rails.application.class.parent_name.downcase
app_env = Rails.env[0...3]
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
:PROMPT_I => "#{ app_name }(#{ app_env })> ",
:PROMPT_N => "#{ app_name }(#{ app_env })| ",
:PROMPT_C => "#{ app_name }(#{ app_env })| ",
:PROMPT_S => "#{ app_name }(#{ app_env })%l ",
:RETURN => "=> %s\n",
:AUTO_INDENT => true,
}
IRB.conf[:PROMPT_MODE] = :RAILS
# SQL helpers
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end
def sql_ex(query)
ActiveRecord::Base.connection.execute(query)
end
def show_tables
sql_ex("show tables").map.flatten
end
def show_cols(klass)
klass.columns.map(&:name).sort
end