Firing Rails Controller Actions From Command Line Console

Hi...
I trying to make this example work:

http://www.misuse.org/science/2007/07/24/firing-rails-controller-actions-from-command-line-console/

I need it for sending out emails and doing a lot of other tasks from a
specific action in a controller.

The error I get is:

rake actions:echo

rake aborted!
A key is required to write a cookie containing the session data. Use
config.action_controller.session = { :key => "_myapp_session", :secret
=> "some secret phrase" } in config/environment.rb

Also require 'action_controller/integration' doesn't work but require
'action_controller' does but yields the error above.

I've tried to specify a key generated through rake secret but still no
luck trying to make it work.
Any help is much appreciated.

I’m sorry if this derails your question, but it would be much better to factor the code so that the behavior your want to invoke is not tied up in the execution of the action. You might have heard smart people say Fat Model Skinny Controller. It is exceptionally good advice.

When you have done this, there are facilities for invoking your models from the command line that are built right into rails. I suggest you investigate the use of custom rake tasks for this purpose.

The road you’re on now is a perilous one. This fellow you linked to is using the rails integration testing framework to do his dirty deeds (that is the ‘require action_controller/integration’ line). Okay if you’re messing around, not okay for doing real work.

-Tyler

The controller action is not that fat. It's just 3 lines which uses
Notifier model to send a bunch of links like password reset url, login
url and all that.
There are realy no other tasks aside from sending out emails. So
perhaps if it's easier to just try Firing model methods than
controller actions, how do you pass urls from a model?

Anyway... I've figured out the problem, Thanks.

If you have time, please share your solution. I had a similar problem
a while back, and ended up just using ActionMailer and creating a mail
object and extracting the body. Other solutions required too much
including different ActionView and ActionController modules ad
nauseum.