# Firing Rails Controller Actions From Command Line Console

**URL:** <https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223>\
**Category:** Rails\
**Created:** [October 31, 2009, 6:31am UTC](https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223 "2009-10-31T06:31:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Katherine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f9ae1b/32.png) [@Katherine](https://www.ruby-forum.com/u/Katherine)\
**Post date:** [October 31, 2009, 6:31am UTC](https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223/1 "2009-10-31T06:31:47Z")

</div>

Hi…  
I trying to make this example work:

[http://www.misuse.org/science/2007/07/24/firing-rails-controller-actions-from-command-line-console/](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.

---

<div class="post-metadata">

**Author:** ![Katherine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f9ae1b/32.png) [@Katherine](https://www.ruby-forum.com/u/Katherine)\
**Post date:** [October 31, 2009, 3:11pm UTC](https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223/2 "2009-10-31T15:11:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Katherine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f9ae1b/32.png) [@Katherine](https://www.ruby-forum.com/u/Katherine)\
**Post date:** [October 31, 2009, 6:47am UTC](https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223/3 "2009-10-31T06:47:36Z")

</div>

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[http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model](http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model)  
. 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[http://railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial](http://railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial)  
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

---

<div class="post-metadata">

**Author:** ![Katherine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f9ae1b/32.png) [@Katherine](https://www.ruby-forum.com/u/Katherine)\
**Post date:** [November 1, 2009, 8:34pm UTC](https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223/4 "2009-11-01T20:34:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Katherine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f9ae1b/32.png) [@Katherine](https://www.ruby-forum.com/u/Katherine)\
**Post date:** [October 31, 2009, 3:23pm UTC](https://www.ruby-forum.com/t/firing-rails-controller-actions-from-command-line-console/178223/5 "2009-10-31T15:23:15Z")

</div>

Anyway… I’ve figured out the problem, Thanks.
