Skip to content

Instantly share code, notes, and snippets.

@patrick99e99
Created August 7, 2009 16:49
Show Gist options
  • Save patrick99e99/164010 to your computer and use it in GitHub Desktop.
Save patrick99e99/164010 to your computer and use it in GitHub Desktop.
def shipping_label
@from_address = Setting.find_by_name("shipping_from_address").address
@to_address = Address.find(params[:file_name].split("_").last)
prawnto :prawn => {
:page_layout => :landscape,
:page_size => [79.2, 252.0],
:left_margin => 0,
:right_margin => 0,
:top_margin => 0,
:bottom_margin => 0 }
end
map.shipping_label 'contacts/shipping_label/:file_name.:format', :controller => 'contacts', :action => 'shipping_label'
address = @to_address # for some weird reason @to_address is null inside the block yet setting a local variable to it outside of the block works.. this is very weird.
from = @from_address
pdf.instance_eval do
font_size 7
bounding_box [0,79], :width => 100, :height => 79 do
padded_box 5 do
text from.label
text [from.street_1, from.street_2].join(" ")
text [from.city, from.region.abbreviation].join(", ")
text from.country.name
end
end
font_size 9
bounding_box [100,59], :width => 152, :height => 59 do
padded_box 5 do
text address.contact.full_name
text [address.street_1, address.street_2].join(" ")
text [address.city, address.region.abbreviation].join(", ")
text address.country.name
end
end
end
<%- @contact.addresses.map_with_index do |address, idx| -%>
<tr class="show">
<%= content_tag :th, @contact.address.size > 1 ? "Addresses:" : "Address:", :rowspan => @contact.addresses.size if idx.zero? %>
<td><%= address.multi_line_with_breaks %><td>
<td class="action"><%= link_to 'Generate Label', shipping_label_path( :format => 'pdf', :file_name => "#{@contact.full_name.underscorize}_#{address.id}") %></td>
</tr>
<%- end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment