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