small medium large xlarge

29 Dec 2014, 05:25
Kevin Weinberg (3 posts)

The Pragmatic Bookshelf suggests you do what is located here:

While that may work, we coded

rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart

at the top of the carts_controller with a def defining the invalid_cart block under the private section at the bottom. If I wanted to put the email notifier trigger in that block (invalid_cart), what is the best way to do that? I am currently doing this

def invalid_cart logger.error "Attempt to access invalid cart #{params[:id]}" @error = "Attempt to access invalid cart #{params[:id]}" ErrorNotifier.error_occured(@error).deliver redirect_to store_url, notice: 'Invalid cart' end

which isn’t exactly DRY considering i’m duplicating the error message, once to display, then once to store and send to the notifier.

2nd question – an occurrence that I don’t understand – when I call “@error.messages” in the notifier email, I get an error, (undefined method `messages’) but when I remove ‘.messages’ it works fine…?

Any help cleaning this up would be appreciated!

Thanks, Kevin

You must be logged in to comment