How to split code between model and controller in Rails?

Both my Rails model and controller code need to write files to the file system.

I would like to combine the logic into one method.

What's the best way to share this method between models and controllers?

Thank!

+2


source to share


2 answers


I think the controller will defer the actual execution of the file write to the model file system. While the controller is allowed to decide when to execute this code, it shouldn't be responsible for implementing it, so this code should really only be in the model.



+2


source


If you really need to do this, you can place the module in / lib and include

wherever needed.



However, if possible, you need your model to take care of this. If you can provide more details, it will be easier for you to steer you in the right direction.

+2


source







All Articles