Sha256: ed7a4c6ad547df72328d6767b56dd3442763f359d9e225a6889daee471eb728c
Contents?: true
Size: 1.76 KB
Versions: 7
Compression:
Stored size: 1.76 KB
Contents
class Manage::CmsSnippetsController < Manage::ApplicationController before_action :check_permissions before_action :block_basic_users cache_sweeper :cms_content_sweeper def index @cms_snippets = CmsSnippet.order(:name) end def new @cms_snippet = CmsSnippet.new render action: 'edit' end def create @cms_snippet = CmsSnippet.new update end def edit @cms_snippet = CmsSnippet.find_by_id(params[:id]) end def update @cms_snippet ||= CmsSnippet.find(params[:id]) @cms_snippet.assign_attributes(cms_snippet_params) begin puts Cms::ContentController.renderer.new('action_dispatch.request.path_parameters' => { controller: '/cms/content', action: 'show', id: CmsPage.new }).render inline: @cms_snippet.content rescue ScriptError, StandardError => e flash.now[:error] = "<pre title=\"#{ERB::Util.html_escape(e.backtrace.join("\n"))}\">#{ERB::Util.html_escape(e.message)}</pre>".html_safe render action: 'edit' and return end if !@cms_snippet.save flash.now[:error] = @cms_snippet.errors.full_messages.join('<br>').html_safe render action: 'edit' else flash[:notice] = 'Snippet saved.' redirect_to action: 'edit', id: @cms_snippet end end protected def check_permissions if !user_has_permission?(:manage_cms) render '/imagine_cms/errors/permission_denied', layout: false return false end end def block_basic_users return true unless UseCmsAccessLevels unless user_has_permission?(:manage_cms_full_access) render '/imagine_cms/errors/permission_denied' return false end end def cms_snippet_params params.require(:cms_snippet).permit(:name, :content) end end
Version data entries
7 entries across 7 versions & 1 rubygems