Sha256: 140255d0ec2c40c67d40cedd9c83a6e9ca2cc596a841a366246ba12bfdb8565e

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

module Refinery
  module <%= class_name.pluralize %>
    module Admin
      class SettingsController < Refinery::AdminController

        before_action :find_setting, :only => [:edit, :update]
        after_action :save_subject_for_confirmation, :save_message_for_confirmation, :save_notification_recipients, :only => :update

        def edit
        end

        def update
            flash[:notice] = t('refinery.crudify.updated', :what => @setting.name.gsub("<%= singular_name %>_", "").titleize)

            if request.xhr? or from_dialog?
              render :text => "<script type='text/javascript'>parent.window.location = '#{refinery.<%= namespacing.underscore %>_admin_<%= plural_name %>_path}';</script>"
            else
              redirect_back_or_default(refinery.<%= namespacing.underscore %>_admin_<%= plural_name %>_path)
            end
        end

      protected
        def find_setting
          setting = params[:id].gsub("<%= singular_name %>_", "")

          Refinery::<%= namespacing %>::Setting.send(setting) if Refinery::<%= namespacing %>::Setting.respond_to?(setting)

          @setting = Refinery::Setting.friendly.find(params[:id])
        end

        def save_notification_recipients
          Refinery::<%= namespacing %>::Setting.notification_recipients = setting_params[:value] if setting_params.include?('value')
        end

        def save_subject_for_confirmation
          Refinery::<%= namespacing %>::Setting.confirmation_subject = setting_params[:subject] if setting_params.include?('subject')
        end

        def save_message_for_confirmation
          Refinery::<%= namespacing %>::Setting.confirmation_message = setting_params[:message] if setting_params.include?('message')
        end

        private

        def setting_params
          params.require(:setting).permit(:value,
            subject: Refinery::I18n.frontend_locales,
            message: Refinery::I18n.frontend_locales)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
refinerycms-forms-1.0.1 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/admin/settings_controller.rb.erb
refinerycms-forms-1.0.0 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/admin/settings_controller.rb.erb