Topic: Controller#action outside of a web request?
I will preface this by saying "I may be approaching the problem entirely wrong", so I will explain what I am attempting to do; followed by the way I'm doing it now and why it seems like I'm not doing it correctly:
I need to regularly upload XML files to a 3rd party (user data, once a day, to an e-mail service).
How I have set this up currently is:
I have a user controller with an emaildata action that returns the proper XML document. This controller/action requires authentication to access (because it's not intended for public consumption). I have a rake script that calls this action via http get request, downloads the xml file, and then uploads it to the 3rd party. I did it this way so the proper MVC stack is utilized - controller does its job, model has the data, view is where the view belongs etc. The cons to doing this are: this controller action requires a public route, I needed to set up special authentication for this route, and I tie up the webserver while this slow/large request happens.
Other options I looked at are having the script do something like:
1) app.get '/users/emaildata'
Avoids the http request, but this still requires a route and authentication.
2) have the controller action itself do the uploading
Still requires some sort of http request, and also puts more logic into the controller which isn't good, and also is a weird use case of the xml view, not actually rendering it
3) create a model class method to do this
requires view stuff in the model, which is frowned upon. Does resolve all the other problems though. i can just call Usermodel::emaildata in the rake script, let the model build up the appropriate xml and send it where it needs to go.
What I would really like to do is something like this in the rake script:
upload = Usercontroller::emaildata upload_my_stuff_to_place(upload)
Because this avoids the http call, I don't need this controller action to be publicly routable (and thus don't need to add authentication to it), and all the view, model, and controller stuff stays where it should be; but I can't see to find a good way to call a controller action from a script without making an http request.
So, what do you all think, any ideas or suggestions? Am I doing this "the rails way" currently, or is there a better way? Or am I crazy and this doesn't make sense?
Thanks in advance.
Last edited by jcantara (2012-02-21 14:37:56)