Created
October 9, 2015 17:45
-
-
Save clayenga/ad2cab9341d347196c43 to your computer and use it in GitHub Desktop.
Error handling comparisons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def SomeController < ApplicationController | |
def some_action_1 | |
line_item = LineItem.find(params[:line_item_id]) | |
user_qty = Integer(params[:user_qty]) rescue nil | |
unless user_qty && (1...line_item.quantity) === user_qty | |
render partial: '/my/error/partial' | |
return | |
end | |
# do some stuff | |
render partial: '/my/main/partial' | |
end | |
def some_action_2 | |
line_item = LineItem.find(params[:line_item_id]) | |
user_qty = Integer(params[:user_qty]) | |
raise ArgumentError unless (1...line_item.quantity) === user_qty | |
# do some stuff | |
render partial: '/my/main/partial' | |
rescue ArgumentError | |
render partial: '/my/error/partial' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment