From 5466cc9301c366895029facf9c8df260d9d865f9 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 22 Sep 2015 22:19:43 -0700 Subject: [PATCH] when remaining costs < $200, pitch harder --- app/helpers/application_helper.rb | 15 +++++++++++++-- app/models/campaign.rb | 4 ++++ app/views/campaigns/show.html.haml | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 812bc8ba..cac277c4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -26,14 +26,25 @@ module ApplicationHelper end end + def cents_to_currency(cents) + number_to_currency(cents / 100.0) + end + def campaign_progress(campaign, &block) if campaign if block_given? content = capture(&block) else + if campaign.remaining < 200_00 + pitch = "We only need #{cents_to_currency(campaign.remaining)} more for #{campaign.name}!" + prompt = "Donate now" + else + pitch = "Help Dress to Impress stay online!" + prompt = "Learn more" + end content = link_to( - content_tag(:span, 'Help Dress to Impress stay online!') + - content_tag(:span, 'Learn more', :class => 'button'), donate_path) + content_tag(:span, pitch) + + content_tag(:span, prompt, :class => 'button'), donate_path) end meter = content_tag(:div, nil, :class => 'campaign-progress', diff --git a/app/models/campaign.rb b/app/models/campaign.rb index 2c5ba43f..6bc11bec 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -7,6 +7,10 @@ class Campaign < ActiveRecord::Base [(progress.to_f / goal) * 100, 100].min end + def remaining + goal - progress + end + def self.current self.where(active: true).first or raise ActiveRecord::RecordNotFound.new("no current campaign") diff --git a/app/views/campaigns/show.html.haml b/app/views/campaigns/show.html.haml index 9af640ca..099f156d 100644 --- a/app/views/campaigns/show.html.haml +++ b/app/views/campaigns/show.html.haml @@ -2,7 +2,7 @@ - if @campaign.progress > 0 = campaign_progress(@campaign) do - We've received #{number_to_currency(@campaign.progress / 100.0)} + We've received #{cents_to_currency(@campaign.progress)} toward #{@campaign.name}. Thanks so much!