Skip to content

Instantly share code, notes, and snippets.

@iateadonut
Created August 21, 2015 09:00
Show Gist options
  • Save iateadonut/879ec688dafd8ecf3bfb to your computer and use it in GitHub Desktop.
Save iateadonut/879ec688dafd8ecf3bfb to your computer and use it in GitHub Desktop.
def json_dealer
render json: Customers.
select('customers.first_name, customers.last_name,
customers.street, customers.city, customers.zip,
customers.home_phone, mobile_phone,
coordinates.latitude, coordinates.longitude, coordinates.distance,
vehicles.make, vehicles.model, vehicles.year').
where(['customers.dealership_id = ?', params[:id]] ).
joins('join coordinates on customers.id = coordinates.customer_id').
joins('join vehicles on customers.id = vehicles.customer_id').
where(['vehicles.make = ?', params[:make]]) if params[:make].presence
end
@rvanlieshout
Copy link

customers = Customers.
      select('customers.first_name, customers.last_name,
        customers.street, customers.city, customers.zip,
        customers.home_phone, mobile_phone,
        coordinates.latitude, coordinates.longitude, coordinates.distance,
        vehicles.make, vehicles.model, vehicles.year').
      where(['customers.dealership_id = ?', params[:id]] ).
      joins('join coordinates on customers.id = coordinates.customer_id').
      joins('join vehicles on customers.id = vehicles.customer_id')

customers.where!(['vehicles.make = ?', params[:make]]) if params[:make].presence

render json: customers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment