Skip to content

Instantly share code, notes, and snippets.

@jonpaul
jonpaul / search.html.erb
Created June 6, 2011 18:40
Instance var for a collection?
<% @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? %>
@jonpaul
jonpaul / rails_admin.rb
Created June 7, 2011 13:37
Where did I go wrong?
bindings[:object].amount.presence.to_f.try(:number_to_currency)
returns >>>
undefined method `number_to_currency' for 139.0:Float
<ul id="listings">
<% @listings.each do |listing| %>
<li <%= "class=stickered" if listing.investor_car? || listing.sticker? %>>
<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) %>
@jonpaul
jonpaul / watchr script
Created June 13, 2011 15:16 — forked from markbates/watchr script
A Watchr script for rails, rspec, and cucumber
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
puts message
image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
@jonpaul
jonpaul / autotest.watchr.rb
Created June 14, 2011 02:12
Auto test + spork via watchr
#!/usr/bin/env watchr
#RUN_ALL_TESTS||=true
#watchr runs through this file a few times
#ensure it only gets set once
unless defined?(GROWL)
$stderr.sync=true
$stdout.sync=true
ENV["WATCHR"] = "1"
GROWL=`which growlnotify`.chomp
@jonpaul
jonpaul / page.rb
Created June 17, 2011 14:17
Returns 'could not find page with ID=page-title'
def to_param
"#{title.downcase.gsub(/[^a-zA-Z0-9]+/, '-').gsub(/-{2,}/, '-').gsub(/^-|-$/, '')}"
end
@jonpaul
jonpaul / page.rb
Created June 20, 2011 21:36
.each do doesn't enumerate my collection(I'm collecting wrong?)
def self.supernav
new_array = ['Home', 'Referring Physicians', 'Patient Pre-Registration', 'Locations', 'About Us', 'Contact Us']
Page.where(:title => new_array)
end
def show
@page = Page.find(params[:id])
@supernav = Page.supnav
@mainnav = Page.mainnav
respond_to do |format|
format.html { if @page.title == 'Home'
render :template => "pages/home"
else
render :html => @page
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def reset_password_email(user)
@user = user
@reset_password_link = edit_password_reset_url(user.perishable_token)
mail(
:to => user.email,
:from => "[email protected]",
:subject => 'Reset password instructions'
def dealerimport_notification(contact, user)
@contact = contact
@user = user
if @contact.(params[:provider]) == 'CarForSale.com'
mail(
:to => '[email protected]',
:from => @user.email,
:subject => 'A New Listings Import Request has been made for CarForSale.'
)