Class: SubscriptionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/subscriptions_controller.rb

Instance Method Summary collapse

Instance Method Details

#change_planObject



38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/subscriptions_controller.rb', line 38

def change_plan
  @subscription = current_user.subscription

  if @subscription.change_plan_to params[:new_plan_id]
    flash.now[:success] = 'The plans. You have changed them.'
  else
    flash.now[:error] = 'Unable to change your plan.'
  end
    render :edit
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/subscriptions_controller.rb', line 5

def create
  @subscription      = Subscription.new params[:subscription]
  @subscription.user = current_user

  @plan = Plan.find params[:subscription][:plan_id]

  if @subscription.save_with_payment
    flash[:success] = 'Subscription added!'
    redirect_to root_path
  else
    flash.now[:error] = 'Unable to add subscription!'
    render template: 'plans/show'
  end
end

#editObject



20
21
22
23
24
# File 'app/controllers/subscriptions_controller.rb', line 20

def edit
  @subscription = current_user.subscription

  @plans = Plan.all
end

#updateObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/subscriptions_controller.rb', line 26

def update
  @subscription = current_user.subscription

  if @subscription.update_with_payment params[:subscription]
    flash.now[:success] = 'Subscription updated!'
    redirect_to root_path
  else
    flash.now[:error] = 'Unable to update billing!'
    render :edit
  end
end