Skip to content

Instantly share code, notes, and snippets.

<%= form_tag(search_path, :method => "get") do %>
<%= label_tag(:q, "Search for:") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Search") %>
<% end %>
# from http://guides.rubyonrails.org/form_helpers.html
@softwaregravy
softwaregravy / Gemfile.rb
Created August 5, 2011 18:36
Need a UUID
require 'uuidtools'
@softwaregravy
softwaregravy / gist:1128135
Created August 5, 2011 18:06
Add an index
add_index :table, :column, :unique => true
remove_index :table, :column
@softwaregravy
softwaregravy / custom_job.rb
Created July 31, 2011 22:41
Pump custom values into hotoad
class CustomJob
def before(job)
Delayed::Context.set(:handler, job.handler)
Delayed::Context.set(:attempt, job.attempts + 1)
Delayed::Context.set(:last_error, job.last_error) if job.last_error
end
def after(job)
Delayed::Context.clear
@softwaregravy
softwaregravy / Questions
Created July 11, 2011 21:42
Magma Rails Give-away
Day Job: Sr. Software Engineer at ThinkNear
Open Source contribution (if any): rails docs and guides
Tell me about your experience with Ruby/Rails: started using it in fall 2010, and have been on it full time every since. Big change from my background in Java (used to work at Amazon.com)
How do you use GitHub: for everything. personal and business. We keep our companies repositories on github. We also use it to collaborate with contractors.
Favorite luchador(es):Rikochet
@softwaregravy
softwaregravy / gist:1054751
Created June 29, 2011 19:51
Always run the job
class JobClass
def perform
begin
#I do stuff here
rescue Exception => e
# catch all exceptions
HoptoadNotifier.notify(e)
ensure
# we want this job to just run continuously, but we don't have an 'auto' way to do that
# so we schedule a new one every time we run
def serializable_hash(options = {})
# TODO exclude the id
options = {:include => [:address, :location, :hours_of_operations, :slow_periods, :discounts],
:except => [:created_at, :updated_at, :creating_user_id]}.merge(options ||= {})
super options
end
def serializable_hash(options = {})
my_options = {:except => [:id, :category, :draws, :owner_identifier, :owner_reference_data,
:primary_image, :related_data, :created_at, :updated_at, :creating_user_id ],
:include => []}.merge(options ||= {})
s = serializable_hash(my_options)
s["address"] = address.serializable_hash_for_public(options)
s
end
@softwaregravy
softwaregravy / render_render
Created March 12, 2011 16:54
calling another template from anther template
<% f.fields_for :member_collection do |builder| %>
<%= render "membrer_collection_fields", :form => builder %>
<% end %>
@softwaregravy
softwaregravy / print_all_attributes
Created March 11, 2011 06:23
Printing out all attributes
<% @merchant_campaign.instance_variable_get(:@attributes).each do |attribute, value| %>
<tr>
<td><%= attribute %></td>
<td><%= value %></td>
</tr>
<% end %>