Sha256: 920a82126674cd29fa5ac133d6ca6c4f78b90c532543581fa080264c571055b6

Contents?: true

Size: 1.74 KB

Versions: 19

Compression:

Stored size: 1.74 KB

Contents

module Spree
  module Admin
    class RecurringsController < Spree::Admin::BaseController
      before_action :find_recurring, :only => [:edit, :update, :destroy]
      before_action :build_recurring, :only => :create

      def index
        @recurrings = Spree::Recurring.undeleted.order('id desc')
      end

      def new
        @recurring = Spree::Recurring.new
      end

      def create
        if @recurring.save
          flash[:notice] = "Recurring created succesfully."
          redirect_to edit_admin_recurring_url(@recurring)
        else
          render :new
        end
      end

      def update
        if @recurring.update_attributes(recurring_params(:update))
          flash[:notice] = "Recurring updated succesfully."
          redirect_to edit_admin_recurring_url(@recurring)
        else
          render :edit
        end
      end

      def destroy
        @recurring.restrictive_destroy
      end

      private

      def find_recurring
        unless @recurring = Spree::Recurring.undeleted.where(id: params[:id]).first
          flash[:error] = "Recurring not found."
          respond_to do |format|
            format.html {redirect_to admin_recurrings_url}
            format.js { }
          end
        end
      end

      def recurring_params(action=:create)
        if action == :create
          params.require(:recurring).permit(:name, :type, :description, :active)
        else
          params.require(:recurring).permit(:name, :description, :active).merge(preference_params)
        end
      end

      def build_recurring
        @recurring = recurring_params.delete(:type).constantize.new(recurring_params)
      end

      def preference_params
        params[ActiveModel::Naming.param_key(@recurring)]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
spree_account_recurring-2.0.0 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.3.1 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.2.1 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.3.0 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.2.0 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.1.5 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.7 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.1.4 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.6 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.5 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.1.3 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.1.2 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.4 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.3 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.2 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.1.1 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.1.0 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.1 app/controllers/spree/admin/recurrings_controller.rb
spree_account_recurring-1.0.0 app/controllers/spree/admin/recurrings_controller.rb