Skip to content

Instantly share code, notes, and snippets.

View patrickberkeley's full-sized avatar

Patrick Berkeley patrickberkeley

View GitHub Profile
# Method borrowed from deprecated Rails Inflector class
def ordinalize(number)
if (11..13).include?(number.to_i % 100)
"#{number}th"
else
case number.to_i % 10
when 1; "#{number}st"
when 2; "#{number}nd"
when 3; "#{number}rd"
else "#{number}th"
@patrickberkeley
patrickberkeley / _form.html.erb
Created April 28, 2009 19:11
Multiple sortable images using Paperclip. Example using a Page model.
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :permalink %><br />
<%= f.text_field :permalink %>
</p>
<p>
rake production radiant:extensions:aggregation:update --trace
** Invoke production (first_time)
** Execute production
** Invoke environment (first_time)
** Execute environment
rake aborted!
Don't know how to build task 'radiant:extensions:aggregation:update'
/opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1704:in `[]'
/opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2026:in `invoke_task'
/opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
<% form_for(@event) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :permalink %><br />
<%= f.text_field :permalink %>
</p>
<% if address_type == 'billing' %>
<% javascript 'dynamic_billing_states' %>
<% else %>
<% javascript 'dynamic_shipping_states' %>
<% end %>
<table>
<tr>
<td class="left"><%= make_label('Country', true) %>
<td class="right">
<script type="text/javascript" charset="utf-8">
function so_clearInnerHTML(obj) {
// so long as obj has children, remove them
while(obj.firstChild) obj.removeChild(obj.firstChild);
};
// create the anchor
eAnchor<%= image.id %> = document.createElement("a");
eAnchor<%= image.id %>.setAttribute("href", "#{image.file.url(:original)}");
eAnchor<%= image.id %>.setAttribute("id", "project_main_image_anchor");
Loading development environment (Rails 2.2.2)
/opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/completion.rb:10:in `require': no such file to load -- readline (LoadError)
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/completion.rb:10
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:252:in `require'
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:250:in `each'
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:250:in `load_modules'
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb.rb:54:in `start'
from /usr/bin/irb:13
def change_main_image
project = Project.find(params[:id])
image = Image.find(params[:image_id])
render :partial => 'main_image', :locals => {:project => project, :image => image}
end
def sort_images
@project = Project.find(params[:id])
@project.images.each do |image|
# we must add one to compensate for the zero based index.
def if_old(date)
"class_name_here" if !date.nil? && date < Date.today
end