DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on

How to write save and save! (bang! in Rails)

I have read lib/banken/loyalty_finder.rb. It's impressive for me. So, I'd like to leave the snippet.

    def loyalty
      loyalty_name.constantize
    rescue NameError
      nil
    end

    def loyalty!
      loyalty || raise(NotDefinedError, "unable to find loyalty `#{loyalty_name}` for `#{controller_name}`")
    end

πŸ”— Parent Note

Top comments (0)