Calling a controller action from script/console or runner


#1

Is there a way to call or invoke a controller method from script/console
or script/runner? The reason is that I’d like to pre-cache some of the
actions on my controller.

The pseudo code below is what I’d like to be able to do:

class MyController < ApplicationController

caches_action :test

def test
puts ‘Hi there’
end

end

script/console:

MyController.test
=> ‘Hi there’

Thanks.


#2

Hi Mark, it seems that you’re trying to invoke an instance using class
method syntax. Thus, you’ll need to do the following in
script/console:

  1. controller = MyController.new

  2. controller.test

Good luck,

-Conrad


#3

I see, cool. Thanks Conrad!

Do you think that’s the best way to pre-cache some of the controller’s
actions?

Thanks.

Conrad T. wrote:

Hi Mark, it seems that you’re trying to invoke an instance using class
method syntax. Thus, you’ll need to do the following in
script/console:

  1. controller = MyController.new

  2. controller.test

Good luck,

-Conrad