Problems with typical Rails controllers and before actions
One of the most common practices when writing controllers in Rails is using before_actions to keep them DRY.
One of the most common practices when writing controllers in Rails is using before_actions to keep them DRY.
Ruby 2.0 came with some pretty useful features like lazy enumerators, keyword arguments, convention for converting to hash. There is also `Module#prepend`, which is not that commonly used, but there are some cases where it really shines. Let's see what we can get from that feature then.
Ever run into the situation where you had to perform some operation based on the value from select field? How did you handle it? Maybe multiple case / switch statements?
Maybe the right question would be: why was it nil in the first place? Could it be avoided? Was the possibility of nil a desired behavior? And why at all is nil even a problem? Let's find out and investigate some usecases.