Both my Rails model and controller code need to write files to the file system.
I would like to consolidate the logic into one method.
What's the best way to share this method across models and controllers?
Thanks!
Both my Rails model and controller code need to write files to the file system.
I would like to consolidate the logic into one method.
What's the best way to share this method across models and controllers?
Thanks!
If you really need to do this, you could place a module in /lib and include
it where needed.
However, if possible you should have your model take care of it. If you can supply some more details, it would be easier to steer you in the correct direction.
I think the controller would defer the actual execution of writing a file to the file system to the model. While the controller is allowed to decide when to execute that code, it should not be responsible for it's implementation, So that code should really only be in the Model.