Class: Koudoku::SubscriptionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Koudoku::SubscriptionsController
- Defined in:
- app/controllers/koudoku/subscriptions_controller.rb
Instance Method Summary collapse
- #cancel ⇒ Object
- #create ⇒ Object
-
#current_owner ⇒ Object
the following two methods allow us to show the pricing table before someone has an account.
- #edit ⇒ Object
- #index ⇒ Object
- #load_owner ⇒ Object
- #load_plans ⇒ Object
- #load_subscription ⇒ Object
- #new ⇒ Object
- #no_owner? ⇒ Boolean
- #redirect_to_sign_up ⇒ Object
- #show ⇒ Object
- #show_existing_subscription ⇒ Object
- #unauthorized ⇒ Object
- #update ⇒ Object
Instance Method Details
#cancel ⇒ Object
112 113 114 115 116 117 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 112 def cancel flash[:notice] = "You've successfully cancelled your subscription." @subscription.plan_id = nil @subscription.save redirect_to owner_subscription_path(@owner, @subscription) end |
#create ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 97 def create @subscription = ::Subscription.new(subscription_params) @subscription.user = @owner if @subscription.save flash[:notice] = "You've been successfully upgraded." redirect_to owner_subscription_path(@owner, @subscription) else flash[:error] = 'There was a problem processing this transaction.' render :new end end |
#current_owner ⇒ Object
the following two methods allow us to show the pricing table before someone has an account. by default these support devise, but they can be overriden to support others.
39 40 41 42 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 39 def current_owner # e.g. "self.current_user" send "current_#{Koudoku.subscriptions_owned_by.to_s}" end |
#edit ⇒ Object
119 120 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 119 def edit end |
#index ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 49 def index # don't bother showing the index if they've already got a subscription. if current_owner and current_owner.subscription.present? redirect_to koudoku.edit_owner_subscription_path(current_owner, current_owner.subscription) end # Load all plans. @plans = ::Plan.order(:display_order).all # Don't prep a subscription unless a user is authenticated. unless no_owner? # we should also set the owner of the subscription here. @subscription = ::Subscription.new({Koudoku.owner_id_sym => @owner.id}) # e.g. @subscription.user = @owner @subscription.send Koudoku.owner_assignment_sym, @owner end end |
#load_owner ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 17 def load_owner unless params[:owner_id].nil? if current_owner.try(:id) == params[:owner_id].try(:to_i) @owner = current_owner else return end end end |
#load_plans ⇒ Object
8 9 10 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 8 def load_plans @plans = ::Plan.order(:price) end |
#load_subscription ⇒ Object
31 32 33 34 35 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 31 def load_subscription ownership_attribute = (Koudoku.subscriptions_owned_by.to_s + "_id").to_sym @subscription = ::Subscription.where(ownership_attribute => current_owner.id).find_by_id(params[:id]) return @subscription.present? ? @subscription : end |
#new ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 69 def new if no_owner? if defined?(Devise) # by default these methods support devise. if current_owner redirect_to new_owner_subscription_path(current_owner, plan: params[:plan]) else redirect_to_sign_up end else raise "This feature depends on Devise for authentication." end else @subscription = ::Subscription.new @subscription.plan = ::Plan.find(params[:plan]) end end |
#no_owner? ⇒ Boolean
27 28 29 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 27 def no_owner? @owner.nil? end |
#redirect_to_sign_up ⇒ Object
44 45 46 47 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 44 def redirect_to_sign_up session["#{Koudoku.subscriptions_owned_by.to_s}_return_to"] = new_subscription_path(plan: params[:plan]) redirect_to new_registration_path(Koudoku.subscriptions_owned_by.to_s) end |
#show ⇒ Object
109 110 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 109 def show end |
#show_existing_subscription ⇒ Object
91 92 93 94 95 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 91 def show_existing_subscription if @owner.subscription.present? redirect_to owner_subscription_path(@owner, @owner.subscription) end end |
#unauthorized ⇒ Object
12 13 14 15 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 12 def render status: 401, template: "koudoku/subscriptions/unauthorized" false end |
#update ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/koudoku/subscriptions_controller.rb', line 122 def update if @subscription.update_attributes(subscription_params) flash[:notice] = "You've successfully updated your subscription." redirect_to owner_subscription_path(@owner, @subscription) else flash[:error] = 'There was a problem processing this transaction.' render :edit end end |