Class: Admin::SubscriptionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::SubscriptionsController
- Defined in:
- app/controllers/tang/admin/subscriptions_controller.rb
Instance Method Summary collapse
- #apply_coupon ⇒ Object
- #coupon ⇒ Object
-
#destroy ⇒ Object
DELETE /subscriptions/1.
-
#edit ⇒ Object
GET /subscriptions/1/edit.
-
#index ⇒ Object
GET /subscriptions.
- #remove_coupon ⇒ Object
-
#show ⇒ Object
GET /subscriptions/1.
-
#update ⇒ Object
PATCH/PUT /subscriptions/1.
Instance Method Details
#apply_coupon ⇒ Object
49 50 51 52 53 54 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 49 def apply_coupon @subscription = Subscription.find(params[:subscription_id]) @coupon = Coupon.find(params[:subscription][:coupon_id]) ApplySubscriptionDiscount.call(@subscription, @coupon) redirect_to admin_subscription_url(@subscription), notice: 'Coupon was successfully applied.' end |
#coupon ⇒ Object
45 46 47 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 45 def coupon @subscription = Subscription.find(params[:subscription_id]) end |
#destroy ⇒ Object
DELETE /subscriptions/1
40 41 42 43 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 40 def destroy @subscription.cancel! redirect_to admin_subscriptions_url, notice: 'Subscription was successfully canceled.' end |
#edit ⇒ Object
GET /subscriptions/1/edit
20 21 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 20 def edit end |
#index ⇒ Object
GET /subscriptions
8 9 10 11 12 13 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 8 def index @subscriptions = Subscription.includes(:customer). where.not(status: :canceled). paginate(page: params[:page]). order("#{Customer.table_name}.email") end |
#remove_coupon ⇒ Object
56 57 58 59 60 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 56 def remove_coupon @subscription = Subscription.find(params[:subscription_id]) RemoveSubscriptionDiscount.call(@subscription) redirect_to admin_subscription_url(@subscription), notice: 'Coupon was successfully removed.' end |
#show ⇒ Object
GET /subscriptions/1
16 17 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 16 def show end |
#update ⇒ Object
PATCH/PUT /subscriptions/1
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/tang/admin/subscriptions_controller.rb', line 24 def update @subscription.end_trial_now = (params[:subscription][:end_trial_now] == '1') if @subscription.end_trial_now params[:subscription]['trial_end(1i)'] = '' params[:subscription]['trial_end(2i)'] = '' params[:subscription]['trial_end(3i)'] = '' end if @subscription.update(subscription_params) redirect_to [:admin, @subscription], notice: 'Subscription was successfully updated.' else render :edit end end |