Prev | Current Page 377 | Next

David Berube

"Practical Reporting with Ruby and Rails"

sort! { |x,y| (x.cost/x.clicks <=> y.cost/y.clicks) }
@results = []
click_sum = 0.0
results_raw.each do |r|
@results << r
click_sum += r.clicks
break if click_sum > @target_clicks
end
@estimated_clicks = click_sum
@avg_cost_per_click = (
@results.inject(0.0) { |sum,r| sum+=r.cost } ) / (
@results.inject(0.0) { |sum,r| sum+= r.clicks } )
CHAPTER 13 n TRACKING YOUR ADS WITH GOOGLE ADWORDS 273
if @excel_view
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = 'attachment; filename="adwords_report.xls"'
end
end
end
Save this file as app/controllers/budget_optimizer_controller.rb.
Next, create a single helper file, as shown in Listing 13-4.
Listing 13-4. Budget Optimizer Helper (app/helpers/budget_optimizer_helper.rb)
module BudgetOptimizerHelper
def format_google_currency(currency_value)
"#{'%0.2f' % (currency_value/10000.0) } cents"
end
end
Save this file as app/helpers/budget_optimizer_helper.rb.
Listing 13-5 shows the file for a layout, which will wrap around your views.


Pages:
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
Na wylot Atari tłumaczenia rosyjski warszawa agencja reklamowa poznań sypialnia