This refacatoring was inspired by this comment on Lobste.rs code on Reddit. Someone noted that the code is a mess, especially CommentsController#create
method. I glanced over suggested solutions and haven't found anything simple and effective.
I have grown to love simple code. Simple code is easy to test, easy to understand, easy to maintain, easy to add features to. Some authors provided even more complicated alternatives to the original mess, sometimes thier solutions where 2-3 times larger (in LOC) than the original spread across files! Tell me about code simplicity!
Benefits (Advantages)
- Uses simple Rails code style for controllers. No service objects, no nothing. Simple
before_action
hooks and private helper methods that encapsulate pieces of logic that can be safely extracted from the main controller method. The logic is pre