Reputation: 740
The value for @c is a parameter set by the user. If there is a value I would like to query for Cars with that condition. If @c is nil I would like to return all of the Car records.
@cars = Car.where('car_type = ?', @c)
Upvotes: 1
Views: 53
Reputation: 124429
You can just use a basic check to see if @c
is blank:
@cars = @c.blank? ? Car.scoped : Car.where('car_type = ?', @c)
Upvotes: 1