Skip to content

Instantly share code, notes, and snippets.

@DemitryT
Created August 18, 2011 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DemitryT/1155356 to your computer and use it in GitHub Desktop.
Save DemitryT/1155356 to your computer and use it in GitHub Desktop.
"Re-send a gift coupon" feature I implemented on a Ruby on Rails application at my last job
# 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"
#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
# only including what I wrote below
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}
end
end
- if @gift.errors.any?
#errorExplanation
%h3= "#{pluralize(@gift.errors.count, 'error')} prohibited this coupon from being resent:"
%ul
- @gift.errors.full_messages.each do |msg|
%li= msg
#edit_gift_info
%h2
Resend gift
= simple_form_for @gift, :url => coupon_gift_path(@coupon.id, @gift.id), :html => { :id => "edit_form", :multipart => true} do |f|
= f.input :friend_name, :label => "Recipient name: ", :disabled => true, :input_html => {:size => "29"}, :required => false
= f.input :friend_email, :label => "Recipient email: ", :required => true, :input_html => {:size => "29"}
= f.input :message, :label => "Optional message: ", :input_html => { :id => "message", :cols => "39", :rows => "4"}, :as => :text
.submit
= f.submit 'Submit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment