donation show form and basic name updating

This commit is contained in:
Emi Matchu 2014-09-09 22:04:17 -05:00
parent 595b1c2fc5
commit 59d5e99312
9 changed files with 83 additions and 2 deletions

View file

@ -13,6 +13,7 @@
@import closet_hangers/index
@import closet_hangers/petpage
@import closet_lists/form
@import donations/show
@import neopets_pages/new
@import neopets_users/form
@import contributions/index

View file

@ -0,0 +1,5 @@
body.donations-show
#thank-you
border: 3px solid $module-border-color
display: block
margin: 0 auto 1em

View file

@ -1,6 +1,20 @@
class DonationsController < ApplicationController
def create
@donation = Donation.create_from_charge(current_user, params[:donation])
render text: @donation.inspect
redirect_to @donation
end
def show
@donation = Donation.from_param(params[:id])
end
def update
@donation = Donation.from_param(params[:id])
@donation.update_attributes params[:donation]
@donation.save!
flash[:success] = 'Donation details saved! ' +
'Also, have we thanked you yet today? Thank you!'
redirect_to @donation
end
end

View file

@ -0,0 +1,22 @@
module DonationsHelper
THANK_YOU_GREETINGS = [
'http://images.neopets.com/new_greetings/1368.gif',
'http://images.neopets.com/new_greetings/466.gif',
'http://images.neopets.com/new_greetings/48.gif',
'http://images.neopets.com/new_greetings/49.gif',
'http://images.neopets.com/new_greetings/64.gif',
'http://images.neopets.com/new_greetings/65.gif',
'http://images.neopets.com/new_greetings/66.gif',
'http://images.neopets.com/new_greetings/67.gif',
'http://images.neopets.com/new_greetings/69.gif',
'http://images.neopets.com/new_greetings/71.gif',
'http://images.neopets.com/new_greetings/72.gif',
'http://images.neopets.com/new_greetings/103.gif',
'http://images.neopets.com/new_greetings/145.gif',
'http://images.neopets.com/new_greetings/420.gif'
]
def thank_you_greeting_url
THANK_YOU_GREETINGS.sample
end
end

View file

@ -1,6 +1,12 @@
class Donation < ActiveRecord::Base
attr_accessible :donor_name
belongs_to :user
def to_param
"#{id}-#{secret}"
end
def self.create_from_charge(user, params)
amount = (BigDecimal.new(params[:amount]) * 100).floor
@ -19,8 +25,19 @@ class Donation < ActiveRecord::Base
donation.amount = amount
donation.charge_id = charge.id
donation.user_id = user.try(:id)
donation.donor_name = user.try(:name)
donation.secret = new_secret
donation.save!
donation
end
def self.new_secret
SecureRandom.urlsafe_base64 8
end
def self.from_param(param)
id, secret = param.split('-', 2)
self.where(secret: secret).find(id)
end
end

View file

@ -0,0 +1,20 @@
- title "Thanks for donating!"
= image_tag thank_you_greeting_url, id: 'thank-you'
%p
%strong Thanks so much!
Your support keeps Dress to Impress online and running smoothly,
and we really, truly couldn't do this without you.
Do you feel the love? Because we do <3
%p
%strong But enough about us. Let's talk about you!
When we brag about you on our donors list, what should we say?
(If you'd rather take care of this later, no worries!
Check your email for a copy of this URL.)
= form_for @donation do |f|
= f.label :donor_name, "What's your name?"
= f.text_field :donor_name, placeholder: 'Anonymous'
= f.submit

View file

@ -78,7 +78,7 @@ OpenneoImpressItems::Application.routes.draw do
only: [:create, :destroy]
end
resources :donations, only: [:create]
resources :donations, only: [:create, :show, :update]
match 'users/current-user/closet' => 'closet_hangers#index', :as => :your_items

View file

@ -5,6 +5,7 @@ class CreateDonations < ActiveRecord::Migration
t.string :charge_id, null: false
t.integer :user_id
t.string :donor_name
t.string :secret
t.timestamps
end

View file

@ -104,6 +104,7 @@ ActiveRecord::Schema.define(:version => 20140910014231) do
t.string "charge_id", :null => false
t.integer "user_id"
t.string "donor_name"
t.string "secret"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end