Forum: Ruby on Rails Calling a controller action from script/console or runner

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mark (Guest)
on 2007-03-27 02:34
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.
Conrad T. (Guest)
on 2007-03-27 02:59
(Received via mailing list)
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 <RETURN>

2) controller.test <RETURN>

Good luck,

-Conrad
Mark (Guest)
on 2007-03-27 03:13
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 <RETURN>
>
> 2) controller.test <RETURN>
>
> Good luck,
>
> -Conrad
This topic is locked and can not be replied to.