Trying to make new instance variables for each item in render :partial

I have a list of people I am using as the collection for a
render :partial. This is for a list of users that is being made into a
pdf. I need to do 3 find calls to find out their attendance for the
last 3 years. The only way I can find to do this is to have the print
function call its view and have the find code in there, but I know
that’s wrong… Please point me in the right direction. Maybe a way to
put the login in the controller ?? Is there a way to add some logic to
the beginning of a render ??

def print
debugger
@today = Date.today
@year = @today.year
@households = Household.find(:all, :order => “last_name,
first_name”)
@churches = Church.find(:all, :order => “name”).map {|u| [u.name, u.id]}

respond_to do |format|
 # format.html # index.html
#  format.xml { head :ok }

format.pdf { send_data render_to_pdf({ :action =>

‘log’, :layout => ‘pdf_report’ }) }
format.pdf { send_data render_to_pdf( :action => ‘print’,
:layout =>
‘pdf_report’),
:filename => "households
for " + Time.now.to_s(:long) + “.pdf” }
end
end

<% @households.each do |@household| %>
  <%  @thisyear =

Visit.find_or_create_by_household_id_and_year(:household_id =>
@household, :year => @year) %>
<% @lastyear =
Visit.find_or_create_by_household_id_and_year(:household_id =>
@household, :year => @year-1) %>
<% @twoyearsago =
Visit.find_or_create_by_household_id_and_year(:household_id =>
@household, :year => @year-2) %>
<%= render :partial=>“print” %>
<% end %>

On May 31, 6:25 am, Bob S. [email protected] wrote:

I have a list of people I am using as the collection for a
render :partial. This is for a list of users that is being made into a
pdf. I need to do 3 find calls to find out their attendance for the
last 3 years. The only way I can find to do this is to have the print
function call its view and have the find code in there, but I know
that’s wrong… Please point me in the right direction. Maybe a way to
put the login in the controller ?? Is there a way to add some logic to
the beginning of a render ??

I think you want to restructure your code a bit. For example, create
an instance method on household for retrieving a view object given a
year. Assuming you had a helper function or a partial for displaying
views your partial for displaying a household wouldn’t need to be much
more complicated than

<%= format_view household.view_for_year @year %>

<%= format_view household.view_for_year @year - 1%>

<%= format_view household.view_for_year @year - 2%>

fred