Skip to content

Instantly share code, notes, and snippets.

@stevekinney
Created September 14, 2014 23:17
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 stevekinney/61920e687c414e164af9 to your computer and use it in GitHub Desktop.
Save stevekinney/61920e687c414e164af9 to your computer and use it in GitHub Desktop.
# Not Good
def show
  @order = Orders.find(params[:id])
end

# Good:
#@user is the logged on user.
def show
  @order = @user.orders.find(params[:id])
end
class LineItemsController < ApplicationController
  before_filter :setup

  #snip many lines

  protected

  def setup
    @invoice = @user.invoices.find(params[:invoice_id]) unless params[:invoice_id].blank?
    @line_item = @invoice.blank? ? @user.line_items.find(params[:id]) : @invoices.line_items.find(params[:id])
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment