Skip to content

Instantly share code, notes, and snippets.

alert('foo');
@diebels727
diebels727 / changes.html.erb
Created April 5, 2011 22:41
Change patterns
#like this ...
<p>
<b>Notes:</b>
<% if @sighting.notes.nil? %>
<span id="notes">&#160;</span>
<% else %>
<span id="notes"><%= @sighting.notes %></span>
<% end %>
</p>
@diebels727
diebels727 / association.rb
Created March 18, 2011 00:13
Super-Meta-Polymorphic
#Where the associations table has sourcable_id,sourcable_type,targetable_id,targetable_type
class Association < ActiveRecord::Base
include Relatable
belongs_to_association :sourcable => :sourcable, :targetable => :targetable
end
#OR _any_ table that we want to be an association table can become one (if the source and target id and type columns do not exist, then the mixin creates them)
class AssociationTables < ActiveRecord::Base
@diebels727
diebels727 / index.html.erb
Created January 13, 2011 16:52
audit view
<% for audit in @audits %>
<tr>
<%if audit.user.present? #<--- Guard against nil users.%>
<td><%= link_to(audit.user.to_label, url_for(audit.user)) %></td>
<%else #<--- Present "Missing" on nil user.%>
<td>Missing</td>
<%end%>
<td><%= audit.kind %></td>
def index
#...
current_page = (params[:page] || 1) # <--- I probably should just 'to_i' both current_page and per_page
per_page = (params[:per_page] || 25) # <---
#...
@reports = WillPaginate::Collection.create(current_page, per_page, @results.count) do |pager|
@diebels727
diebels727 / gist:743532
Created December 16, 2010 15:37
user.rb
#Within the user model
...
#READONLY! Sets all of the user tokens to read-only.
def readonly!
self.tokens.each do |t|
t.capabilities = [:list,:view,:search]
end
end
#Trying to figure out why Report.all returns this:
irb(main):006:0> a = Report.all
=> [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,