Searching purchase records, with or without a vendor criterion
The simplest refactor would be:

# this is the base query
requests = PurchaseRequest.includes(:purchase_order)
             .where(:created_at =&gt; @date_start..@date_end)
             .where(:total_cost =&gt; @cost_beginning..@cost_end)

# then we add additional conditions if required 
requests =
  unless @vendor == "0" # if vendor, get specific purchase request
    request.where("purchaseorder.VendorRef_ListID = ?", @vendor)
  end


If you find that you do certain queries often, the it's probably a chance to use scopes.  You may already know about scopes, but if not, check out Mastering ActiveRecord and Arel.

class PurchaseRequest &lt; ActiveRecord::Base
  has_one :purchase_order

  # requests within a certain data
  scope :date_between, -&gt;(date_range) {
    where(:created_at =&gt; date_range)
  }

  # requests with a certain cost range
  scope :cost_between, -&gt;(date_range) {
    where(:total_cost =&gt; date_range)
  }

  # find request for a specific vendor
  scope :for_vendor, -&gt;(vendor) {
    # this scope does an inner join to purchase_order and adds
    # a condition that the PurchaseOrder must belong to a specific
    # vendor.  That is, only requests matching the vendor are returned
    joins(:purchase_order).merge( PurchaseOrder.for_vendor(vendor) )
  }
end

class PurchaseOrder &lt; ActiveRecord::Base
  # purchase orders belonging to a specific vendor
  scope :for_vendor, -&gt;(vendor) {
    where(:VendorRef_ListID =&gt; vendor)
  }
end


So with scopes added, you can now refactor your code like so:

# this is the base query
requests = PurchaseRequest.includes(:purchase_order)
             .date_between(@date_start..@date_end)
             .cost_between(@cost_beginning..@cost_end)

# if vendor, get specific request
requests = request.for_vendor(@vendor) unless @vendor == "0"