On Sun, Oct 2, 2011 at 10:32, Philrup
<phil-8098yiAR632akBO8gow8eQ@public.gmane.org> wrote:
> the sales guys want a "print-all" function, that prints
> out the 40 or so product details (a page a product) using the Show
> product format, so they dont have to move through each product
> printing them individually; the resulting print-out makes a good
> catalogue which they can then easily update.
I haven''t done anything with formatting output for print, so take this
with a grain of salt, but methinks this ought to work:
- First, I assume you have a button or link or whatever that goes to
some URL that''s supposed to give them a printable catalog, and that we
can control this URL so as to make it point to a given action of a
given controller.
- In the controller, load up an array, let''s call it @products, with
all the products, including all the details that go into the catalog.
You can use the :include option on the search to make sure that
they''re grabbed off any associated objects. You put that logic either
in the controller itself, or better, in the model, exposing some call
like Product.get_all_for_catalog. (If you want to print multiple
types of catalog, you could even have that take some filtering args,
in which case the "all" part might be misleading, and maybe some
format identification, which could determine which details to
include.) So your controller might contain something like "@products
= Product.get_for_catalog({ :which => :all, :format => :print })".
- In the view, output whatever front material you want (cover, ToC,
etc.), iterate over @products (outputting the description), and
finally output whatever back material you want (order form, index,
back cover, etc.). You could use the existing HTML description
output, or alternately put it all in a PDF document with a library
like Prawn. If you want, you can force a page break between each, or
use some kind of pagination helper like will_paginate. (Depends how
long your product descriptions are.) Iterating over it might look
something like:
<% @products.each do |prod| %>
<%= render_partial product_print, prod %>
<% end %>
Be careful which lines you have the = sign on; that''s what tells ERb
to actually show it, not just do it.
-Dave
--
LOOKING FOR WORK, preferably Ruby on Rails, in NoVa/DC; see main web site.
Main Web Site: davearonson.com
Programming Blog: codosaur.us
Excellence Blog: dare2xl.com
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.