Calling an ApplicationController method from console in Rails
ruby, ruby-on-rails, ruby-on-rails-3
Solution
Another, very simple way to do this is to use an instance of `ApplicationController` itself.
ApplicationController < ActionController::Base
def example
"O HAI"
end
end
Then in the console, you can do the following:
>> ApplicationController.new.example
This will output the following:
O HAI
This, of course, has the restriction of not having access to everything a normal request would, such as the `request` object itself. If you need this, as the Patrick Klingemann suggested, you could use the debugger... I personally recommend using Pry:
- Pry on RubyGems.org
- RailsCast: Pry with Rails
This is likely much too late for you, but hopefully it will help someone in the future.
Problem
In Rails, supposing that the file is already loaded, how it is possible to call `my_method` from this example from console? ``` # some_file.rb class MyClass < ApplicationController::Base def my_method(args) ```