Bob Smith
2010-Jul-29 04:45 UTC
Trying to do a user list and getting double render errors..
Here is where I am now. A render :partial at the **** would solve my problem, but another render doesn''t seem to be allowed. Render_pdf uses the only one allowed. Is there another way to do this? At the moment, it works fine, but only gives me 1 user, even though it makes the collections for each user. Controller def print @households = Household.find(:all, :order => "last_name, first_name") @households.each { |@household| @today = Date.today @year = @today.year @churches = Church.find(:all, :order => "name").map {|u| [u.name, u.id]} @thisyear Visit.find_all_by_year_and_household_id(Date.today.year, @household.id) @lastyear Visit.find_all_by_year_and_household_id(Date.today.year-1, @household.id) @yearbefore Visit.find_all_by_year_and_household_id(Date.today.year-2, @household.id) **** } date=`date +%Y%m%d-%H:%M` respond_to do |format| format.pdf { send_data render_to_pdf( :action => ''print'', :layout => ''pdf_report''), :filename => "Household_List_for_" + date } end end First view <!---<style type="text/css"> td{ text-align: right;} --> <% javascript_include_tag :defaults %> debugger <% get_totals(@household) %> <pre><h3 style="text-align:center;font-size: 24px;color:blue;width=100%">Food Shelf</h3> <% form_for @household, :url => household_path(@household), :html => { :method => ''put'' } do |household| %> <table border=1 width="100%"> <td colspan="2"> <table><td>Family Size </td><td style="color:red"><big><%= @family%></ big></td><td> 0-4 Years </td><td style="color:red"><big><%@under5 %></big></td><td> 5-17 Years </td><td style="color:red"><big><%= @child %></big></td><td> 18-64 Years </ td><td style="color:red"><big><%= @adult %></big></td><td> 65 & Over <td></td><td style="color:red"><big><%= @senior %></big></td></ table> <tr><td width="70%" valign="top"> <%= render :partial => ''household'', :object => @household %> </td> <td class="people " width="30%" valign="top"> <%= render :partial => ''people'', :object => @household %> </td> </tr> <tr> debugger <table> <tr><h4>Visits to Foodshelf</h4></tr> <tr><td class="visit" width="33%"> <b>Month of <%= Date.today.year %></b> <table border=1 width="30%"> <tr><th width=30%>Monthly</th> <th width=10%></th> <th width=60%><b>Bread & Veg only for Week</b></th></tr> <th width=5%>1</th> <th width=5%>2</th> <th width=5%>3</th> <th width=5%>4</th> <th width=5%>5</th> </tr> <%= render :partial => ''visit'', :object => @thisyear %> </table> </td> <td class="visit2" width="33%"> <b>Month of <%= Date.today.year-1 %></b> <table border=1 width="30%"> <tr><th width=30%>Monthly</th> <th width=10%></th> <th width=60%><b>Bread & Veg only for Week</b></th></tr> <th width=5%>1</th> <th width=5%>2</th> <th width=5%>3</th> <th width=5%>4</th> <th width=5%>5</th> </tr> <%= render :partial => ''visit'', :object => @lastyear %> </table> </td> <td class="visit" width="33%"> <b>Month of <%= Date.today.year-2 %></b> <table border=1 width="30%"> <tr><th width=30%>Monthly</th> <th width=10%></th> <th width=60%><b>Bread & Veg only for Week</b></th></tr> <th width=5%>1</th> <th width=5%>2</th> <th width=5%>3</th> <th width=5%>4</th> <th width=5%>5</th> </tr> <%= render :partial => ''visit'', :object => @yearbefore %> </table> </td> </pre> <% end %> </table> <!-- PAGE BREAK --> -- 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.
Bob Smith
2010-Aug-02 19:54 UTC
Re: Trying to do a user list and getting double render errors..
Finally found a way around this. Only 1 render is allowed at the controller level, but a view can have as many as wanted, so.. Leave the only allowed render in the controller for render_pdf, and do a find(:all) in the controller. In the view with the same name as the controller action, do a <%= render :partial => ''whatever'', :object => @variable_from_controller %> next make a partial view called _whatever.html.erb or _whatever.erb for pdf output. The variable holding one record from the list will be called whatever, with no @ before it. This partial is where whatever output is wanted per record should be done. Bob <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> On Jul 29, 12:45 am, Bob Smith <bsm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here is where I am now. A render :partial at the **** would solve my > problem, but another render doesn''t seem to be allowed. Render_pdf > uses the only one allowed. Is there another way to do this? > At the moment, it works fine, but only gives me 1 user, even though it > makes the collections for each user. > > Controller > def print > @households = Household.find(:all, :order => "last_name, > first_name") > @households.each { |@household| > @today = Date.today > @year = @today.year > @churches = Church.find(:all, :order => "name").map {|u| > [u.name, u.id]} > @thisyear > Visit.find_all_by_year_and_household_id(Date.today.year, > @household.id) > @lastyear > Visit.find_all_by_year_and_household_id(Date.today.year-1, > @household.id) > @yearbefore > Visit.find_all_by_year_and_household_id(Date.today.year-2, > @household.id) > **** > } > date=`date +%Y%m%d-%H:%M` > respond_to do |format| > format.pdf { send_data render_to_pdf( :action => ''print'', > :layout => ''pdf_report''), > :filename => > "Household_List_for_" + date } > end > end > > First view > > <!---<style type="text/css"> > td{ text-align: right;} > --> > <% javascript_include_tag :defaults %> > > debugger > <% get_totals(@household) %> > > <pre><h3 style="text-align:center;font-size: > 24px;color:blue;width=100%">Food Shelf</h3> > <% form_for @household, :url => household_path(@household), :html => > { :method => ''put'' } do |household| %> > <table border=1 width="100%"> > <td colspan="2"> > <table><td>Family Size </td><td style="color:red"><big><%= @family%></ > big></td><td> 0-4 Years </td><td style="color:red"><big><%> @under5 %></big></td><td> 5-17 Years </td><td > style="color:red"><big><%= @child %></big></td><td> 18-64 Years </ > td><td style="color:red"><big><%= @adult %></big></td><td> 65 & > Over <td></td><td style="color:red"><big><%= @senior %></big></td></ > table> > > <tr><td width="70%" valign="top"> > <%= render :partial => ''household'', :object => @household %> > </td> > <td class="people " width="30%" valign="top"> > <%= render :partial => ''people'', :object => @household %> > </td> > </tr> > <tr> > debugger > <table> > <tr><h4>Visits to Foodshelf</h4></tr> > <tr><td class="visit" width="33%"> > <b>Month of <%= Date.today.year %></b> > <table border=1 width="30%"> > <tr><th width=30%>Monthly</th> > <th width=10%></th> > <th width=60%><b>Bread & Veg only for Week</b></th></tr> > <th width=5%>1</th> > <th width=5%>2</th> > <th width=5%>3</th> > <th width=5%>4</th> > <th width=5%>5</th> > </tr> > <%= render :partial => ''visit'', :object => @thisyear %> > </table> > </td> > <td class="visit2" width="33%"> > <b>Month of <%= Date.today.year-1 %></b> > <table border=1 width="30%"> > <tr><th width=30%>Monthly</th> > <th width=10%></th> > <th width=60%><b>Bread & Veg only for Week</b></th></tr> > <th width=5%>1</th> > <th width=5%>2</th> > <th width=5%>3</th> > <th width=5%>4</th> > <th width=5%>5</th> > </tr> > <%= render :partial => ''visit'', :object => @lastyear %> > </table> > </td> > <td class="visit" width="33%"> > <b>Month of <%= Date.today.year-2 %></b> > <table border=1 width="30%"> > <tr><th width=30%>Monthly</th> > <th width=10%></th> > <th width=60%><b>Bread & Veg only for Week</b></th></tr> > <th width=5%>1</th> > <th width=5%>2</th> > <th width=5%>3</th> > <th width=5%>4</th> > <th width=5%>5</th> > </tr> > <%= render :partial => ''visit'', :object => @yearbefore %> > </table> > </td> > </pre> > <% end %> > </table> > <!-- PAGE BREAK -->-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.