Sha256: f1f1cddec288a6b3dfcdb5142980a000bca2f7a363a93938014175b48f1cf61b

Contents?: true

Size: 1.44 KB

Versions: 27

Compression:

Stored size: 1.44 KB

Contents

class PlansController < ApplicationController
  layout Saucy::Layouts.to_proc

  def index
    @plans = Plan.ordered
    notify_observers_of_plan_list_view
  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_of_plan_list_view
    Saucy::Notifications.notify_observers("plan_list_viewed",
                                          :request => request)
  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

27 entries across 27 versions & 1 rubygems

Version Path
saucy-0.16.1 app/controllers/plans_controller.rb
saucy-0.16.0 app/controllers/plans_controller.rb
saucy-0.15.2 app/controllers/plans_controller.rb
saucy-0.15.1 app/controllers/plans_controller.rb
saucy-0.15.0 app/controllers/plans_controller.rb
saucy-0.14.5 app/controllers/plans_controller.rb
saucy-0.14.3 app/controllers/plans_controller.rb
saucy-0.10.10 app/controllers/plans_controller.rb
saucy-0.14.2 app/controllers/plans_controller.rb
saucy-0.14.1 app/controllers/plans_controller.rb
saucy-0.14.0 app/controllers/plans_controller.rb
saucy-0.13.3 app/controllers/plans_controller.rb
saucy-0.13.2 app/controllers/plans_controller.rb
saucy-0.10.9 app/controllers/plans_controller.rb
saucy-0.10.8 app/controllers/plans_controller.rb
saucy-0.13.1 app/controllers/plans_controller.rb
saucy-0.13.0 app/controllers/plans_controller.rb
saucy-0.12.5 app/controllers/plans_controller.rb
saucy-0.12.4 app/controllers/plans_controller.rb
saucy-0.12.3 app/controllers/plans_controller.rb