In my Rails application I have three models: articles, sentences and a join model article_sentences.
The @article.article field contains several paragraphs of text. Sentences are delimited by full stops and there are also blank lines.
When the user creates or edits an article, I would like behind the scenes code to parse the value of the text in @article.article and create an entry for each full stop delimited sentence in the sentences table.
Would this type of “post-save” code go in the create method in the articles controller? Any suggestions on how to do the parsing?
Any place where you store the (modified) article, is a good place to parse the (updated) contents.
So in the regular situation that would be in
createmethod, as it stores a new articleupdatemethod as it stores an updated version of the article (dpending on your requirements, you might remove the sentences before storing the updated version and parse the article afterwardsIf you do not use the default REST implementation you need to find your custom locations where you store/update articles.