Skip to content

Commit

Permalink
Label making is made of WIN!
Browse files Browse the repository at this point in the history
  • Loading branch information
sermoa committed Dec 12, 2008
1 parent 7db759f commit 4b7bb00
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -1,3 +1,6 @@
[submodule "vendor/plugins/basic_model"]
path = vendor/plugins/basic_model
url = git://github.com/topfunky/basic_model.git
[submodule "vendor/plugins/pdf_label_maker"]
path = vendor/plugins/pdf_label_maker
url = git://github.com/sermoa/pdf_label_maker.git
7 changes: 7 additions & 0 deletions app/controllers/contacts_controller.rb
Expand Up @@ -2,6 +2,13 @@ class ContactsController < ApplicationController

def index
@contacts = Contact.view(database_name, 'contacts/by_last_name-map')
respond_to do |format|
format.pdf do
pdf = PdfLabelMaker.avery_labels(@contacts.rows)
send_data pdf.render, :filename => 'labels.pdf', :type => 'application/pdf'
end
format.html
end
end

def edit
Expand Down
9 changes: 8 additions & 1 deletion app/models/contact.rb
@@ -1,7 +1,14 @@
class Contact < BasicModel
class Contact < BasicModel

def full_name
"#{first_name} #{last_name}"
end

def label_lines
returning Array.new do |arr|
arr << full_name
address.split("\r\n").each{|line| arr << line}
end
end

end
2 changes: 2 additions & 0 deletions app/views/contacts/index.html.erb
@@ -1,5 +1,7 @@
<h1>Contacts</h1>

<p><%= link_to('New contact', new_contact_path) %></p>

<% @contacts.rows.each do |contact| -%>

<h2><%= contact.full_name %></h2>
Expand Down
4 changes: 4 additions & 0 deletions config/environment.rb
Expand Up @@ -65,3 +65,7 @@
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
end


Mime::Type.register 'application/pdf', :pdf

1 change: 1 addition & 0 deletions vendor/plugins/pdf_label_maker
Submodule pdf_label_maker added at 446b2c

0 comments on commit 4b7bb00

Please sign in to comment.