Let's say I wanted a greeting every time the Rails console comes up:
Scotts-MBP-4:ucode scott$ rails c
Loading development environment (Rails 4.2.1)
Hello there! I'm a custom greeting
2.1.5 :001 >
Where would I put the puts 'Hello there! I\'m a custom greeting'
statement?
Another Stackoverflow answer suggested, and I've read this elsewhere too, that I can put that in an initializer like this:
# config/initializers/console_greeting.rb
if defined?(Rails::Console)
puts 'Hello there! I\'m a custom greeting'
end
That doesn't work for me though :(. Even without the if defined?(Rails::Console)
I still don't get output. Seems like initializers are not run when I enter a console, despite what others suggest.
if defined?(Rails::Console)
, and have never had an issue... I wonder if there is something else at play, here? – Testudinalrails s
. So the initializer is getting executed. Just not when launching a console. Only when launching the whole server. – Lithographbwerth@worth:~/rails/my_site$ bundle exec rails c
"Devise monkey patch for v 3.4.1. Check before moving on"
Loading development environment (Rails 4.0.2)
– Testudinalp ('Devise monkey patch for v 3.4.1. Check before moving on')
is the first line inconfig/initializers/devise_minkey_patch.rb
... What other gems are you using? Any logger shenanigains? – Testudinal