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.
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?
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
Controllerhttp://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
taskshttp://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
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.
Anyway… I’ve figured out the problem, Thanks.