Skip to content

Instantly share code, notes, and snippets.

@clayenga
clayenga / gist:ad2cab9341d347196c43
Created October 9, 2015 17:45
Error handling comparisons
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
@clayenga
clayenga / gist:4112534
Created November 19, 2012 18:26
SQL question (total book prices for each genre)
books:
id | title | price | genre_id
--------------------------------------------------
1 | Gone With the Wind | 15 | 1
2 | The Lord of the Rings | 30 | 2
3 | The Hobbit | 10 | 2
4 | Pride and Predjudice | 10 | 1
5 | Complete Sherlock Holmes | 9 | 4