Sha256: 81a1d11c33cc30e30575a982b86990905bcdadea807fcc6af6bc31c067d8e69c

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

class PlansController < ApplicationController
  layout Saucy::Layouts.to_proc

  def index
    @plans = Plan.ordered
  end

  def edit
    @plans = Plan.ordered
    @account = current_account
  end

  def update
    @plans = Plan.ordered
    @account = current_account
    from_plan = @account.plan

    if @account.save_customer_and_subscription!(params[:account])
      to_plan = @account.plan
      notify_observers_of_plan_change(from_plan, to_plan)
      redirect_to edit_account_path(@account), :notice => t('.update.notice', :default => "Plan changed successfully")
    else
      render :edit
    end
  end

  private

  def notify_observers_of_plan_change(from_plan, to_plan)
    notify_observers("plan_upgraded",   from_plan, to_plan) if from_plan.price < to_plan.price
    notify_observers("plan_downgraded", from_plan, to_plan) if from_plan.price > to_plan.price
  end

  def notify_observers(event_name, from_plan, to_plan)
    Saucy::Notifications.notify_observers(event_name,
                                          :account   => @account,
                                          :request   => request,
                                          :from_plan => from_plan,
                                          :to_plan   => to_plan)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
saucy-0.10.6 app/controllers/plans_controller.rb
saucy-0.10.5 app/controllers/plans_controller.rb
saucy-0.10.4 app/controllers/plans_controller.rb
saucy-0.10.3 app/controllers/plans_controller.rb
saucy-0.10.2 app/controllers/plans_controller.rb
saucy-0.10.1 app/controllers/plans_controller.rb
saucy-0.10.0 app/controllers/plans_controller.rb
saucy-0.9.1 app/controllers/plans_controller.rb
saucy-0.9.0 app/controllers/plans_controller.rb