Sha256: fb6d77e43b1d4cd88c1dc3afa66e60ea6b7aeac2e3c7cbf7ffb70835b2580024

Contents?: true

Size: 1.91 KB

Versions: 28

Compression:

Stored size: 1.91 KB

Contents

module Workarea
  module Admin
    class SegmentRulesController < Admin::ApplicationController
      before_action :find_segment, except: :geolocation_options
      before_action :find_rules, except: :geolocation_options
      before_action :find_rule, except: [:index, :geolocation_options]

      def index
      end

      def geolocation_options
        @results = Segment::Rules::GeolocationOption.search(params[:q])
      end

      def create
        if @rule.save
          flash[:success] = t('workarea.admin.segment_rules.flash_messages.saved')
          redirect_to return_to || segment_rules_path(@segment)
        else
          flash[:error] = t('workarea.admin.segment_rules.flash_messages.error')
          render :index, status: :unprocessable_entity
        end
      end

      def update
        if @rule.update_attributes(params[:rule])
          flash[:success] = t('workarea.admin.segment_rules.flash_messages.saved')
          redirect_to return_to || segment_rules_path(@segment)
        else
          flash[:error] = t('workarea.admin.segment_rules.flash_messages.error')
          render :edit, status: :unprocessable_entity
        end
      end

      def destroy
        @rule.destroy
        flash[:success] = t('workarea.admin.segment_rules.flash_messages.destroyed')
        redirect_to return_to || segment_rules_path(@segment)
      end

      private

      def find_segment
        model = Segment.find(params[:segment_id])
        @segment = SegmentViewModel.wrap(model, view_model_options)
      end

      def find_rules
        @segment_rules = @segment.rules.select(&:persisted?)
      end

      def find_rule
        @rule = if params[:id].present?
          @segment.rules.where(id: params[:id]).first
        else
          klass = "Workarea::Segment::Rules::#{params[:rule_type].to_s.camelize}"
          @segment.model.rules.build(params[:rule], klass.constantize)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.15 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.14 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.13 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.12 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.11 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.10 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.9 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.8 app/controllers/workarea/admin/segment_rules_controller.rb
workarea-admin-3.5.7 app/controllers/workarea/admin/segment_rules_controller.rb