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)