public
Created

"Re-send a gift coupon" feature I implemented on a Ruby on Rails application at my last job

  • Download Gist
_coupon_block.html.haml
Haml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# only including what I helped write below
 
.coupon_list
- array_of_coupons.each do |coupon|
%div
- if redeemed
%span.cross_out
= "#" + coupon.uid
%span.green
= link_to (coupon.user_redeemed ? "Mark as New" : "Mark as Used"), '#', :class => 'user_redeemed', :rel => toggle_user_redeemed_coupon_path(coupon)
-elsif !redeemed && !coupon.gift
%span
= "#" + coupon.uid
%span.redeemed
= link_to 'Print', "/offers/#{offer_option.offer_id}/coupons/#{coupon.id}.pdf"
|
= link_to (coupon.user_redeemed ? "Mark as New" : "Mark as Used"), '#', :class => 'user_redeemed', :rel => toggle_user_redeemed_coupon_path(coupon)
-else
%span
= "#" + coupon.uid
%span.redeemed
= link_to 'Print', "/offers/#{offer_option.offer_id}/coupons/#{coupon.id}.pdf"
|
= link_to 'Resend', edit_coupon_gift_path(coupon.id, coupon.gift.id), :rel => "facebox"
consumer_index.html.haml
Haml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 
#content
%h1
NEW DEALS
%hr
 
= render 'coupon_block', :offer_options_hash => @unredeemed_hash, :redeemed => false
 
%h1
REDEEMED
%hr
 
= render 'coupon_block', :offer_options_hash => @redeemed_hash, :redeemed => true
 
 
- unless @gifts_hash.empty?
%h1#gifts
GIFTS
%hr
= render 'coupon_block', :offer_options_hash => @gifts_hash, :redeemed => false
 
= link_to "Back", :back
 
 
- if flash[:offer_id]
#share_reminder_window.hidden
= render :partial => 'shares/share_reminder', :locals => { :offer => @offer, :user => current_user, :image_name => (@offer && @offer.image ? @offer.image.image_file_name : "blank.png" ) }
coupons_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#can't include everything, below is what I helped write
 
def consumer_index
include_facebox
@custom_csses << "compiled/gifts/edit.css"
 
if current_user
unredeemed_array = []
redeemed_array = []
gifts_array = []
current_user.coupons.each do |c|
unredeemed_array << c unless c.user_redeemed || c.gift
redeemed_array << c if c.user_redeemed
gifts_array << c if c.gift
end
 
@unredeemed_hash = unredeemed_array.sort_by{|c| c.offer_option.offer.title }.group_by { |x| x.offer_option }
@redeemed_hash = redeemed_array.sort_by{|c| c.offer_option.offer.title }.group_by { |x| x.offer_option}
@gifts_hash = gifts_array.sort_by{|c| c.offer_option.offer.title }.group_by { |x| x.offer_option}
@offer = Offer.find(flash[:offer_id]) if flash[:offer_id]
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.