I've a Ruby class that I will use only for console, it monkey patches ActiveRecord::Base
with some shortcuts like ua
for update_attribute
and I don't want to load it when running rails server
but only when running the rails console
command.
What is the way to achieve this?
rails console
defines Rails::Console
So you can do
if defined?(Rails::Console)
# this runs only in rails console
end
Another approach would be to use config/application.rb
:
module MyApplication
class Application < Rails::Application
console do
require 'my_console_file'
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With