On May 31, 6:25 am, Bob Smith <bsm...@gmail.com> 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
>
> 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 %>
--
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@googlegroups.com.
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.
No comments:
Post a Comment