Skip to content

Instantly share code, notes, and snippets.

View patrickberkeley's full-sized avatar

Patrick Berkeley patrickberkeley

View GitHub Profile
a = [1, 2]
b = 'cat'
a.each {|b| c = b * a[1]}
a #=> [1, 2]
b #=> 2
defined?(c) #=> nil
class Image < Asset
has_attached_file :file,
:styles => { :thumb => '75x75#', :small => '250x250>', :medium => '416x416>', :full => '792x792>' },
:default_style => :medium,
:url => "/assets/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/:id/:style/:basename.:extension"
validates_attachment_content_type :file, :content_type => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif']
end
<%= link_to document.file.original_filename.parameterize, {:controller => 'documents', :action => 'show', :args => [:document => document.file.url(:original)]}, :class => 'document' %>
def if_old(date)
"class_name_here" if !date.nil? && date < Date.today
end
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.
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
<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");
<% 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">