Created
June 6, 2011 18:40
-
-
Save jonpaul/1010793 to your computer and use it in GitHub Desktop.
Instance var for a collection?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @listings.each do |listing| %> | |
<li> | |
<input type="hidden" name="listing_id" value="<%= listing.id %>" class="listing_id" /> | |
<% if listing.featured? %> | |
<%= image_tag("icons/featured_sticker.png", :class => "featuredSticker")%> | |
<% end %> | |
<div class="img"> | |
<% if listing.primary_photo_id.blank? && !listing.vehicle_listing_images.first.nil? %> | |
<%= link_to(image_tag(listing.vehicle_listing_images.first.vehicle.url(:search), :class => 'primary_image'), listing) %> | |
<% elsif !listing.primary_photo_id.blank? %> | |
<%= link_to(image_tag(VehicleListingImage.find(listing.primary_photo_id).vehicle.url(:search), :class => 'primary_image'), listing) %> | |
<% else %> | |
"Sorry, No Images for this Product." | |
<% end %> | |
</div> | |
. | |
. | |
. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search | |
params[:search][:zipcode_distance] = nil if params[:search][:zipcode_within].blank? | |
unless params[:search][:zipcode_distance].blank? | |
@search = VehicleListing.includes(:dealer).zipcode_distance(params[:search][:zipcode_distance]).search(params[:search]) | |
else | |
@search = VehicleListing.search(params[:search]) | |
end | |
@search_total = @search.all | |
if params[:page].blank? | |
params[:page] = 1 | |
offset = false | |
end | |
@listings = WillPaginate::Collection.create(params[:page], 25) do |pager| | |
listings = VehicleListing.limit(25) | |
listings = listings.offset(params[:page].to_i) unless offset == false | |
listings = listings.search(params[:search]).all | |
pager.replace(listings) | |
pager.total_entries = @search_total.count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment