I have a Sentence model that will contain a single sentence in the body column. It is important to have only one sentence per row. However, users may enter more than one sentence in the form. Not a problem. I actually want to encourage that.
So what I need to do is split the sentences and save only one sentence per row. I am able to do this in the controller fairly easily (a simple .split(“. “) will do it), however that becomes a bit unmaintainable after time. I really feel like the model should handle this.
So what I am thinking is doing some sort of before_save hook in my Sentence model and doing the split in there. Obviously that creates some problems of its own as well.
Is there a better way to do it?
I would refractor it into a class method, such as:
Semi-Pseudo Code:
So you could call in your controller: