Skip to content

Instantly share code, notes, and snippets.

@qcam
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qcam/11471812 to your computer and use it in GitHub Desktop.
Save qcam/11471812 to your computer and use it in GitHub Desktop.
Rescue Error in Controller

Use rescue_form to avoid code duplication in Controller

class DealsController < ApplicationController
  before_filter :authenticate_user!, except: [:index, :show, :list]
  before_filter :authenticate_proposer, only: [:edit]

  rescue_from StandardError, with: :show_errors
  rescue_from Order::OrderNotFound, with: :show_errors
  
  protected
  def show_errors(exception)
    flash[:alert] = exception.message
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment