Class: Manage::CmsSnippetsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/manage/cms_snippets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
# File 'app/controllers/manage/cms_snippets_controller.rb', line 16

def create
  @cms_snippet = CmsSnippet.new
  update
end

#editObject



21
22
23
# File 'app/controllers/manage/cms_snippets_controller.rb', line 21

def edit
  @cms_snippet = CmsSnippet.find_by_id(params[:id])
end

#indexObject



7
8
9
# File 'app/controllers/manage/cms_snippets_controller.rb', line 7

def index
  @cms_snippets = CmsSnippet.order(:name)
end

#newObject



11
12
13
14
# File 'app/controllers/manage/cms_snippets_controller.rb', line 11

def new
  @cms_snippet = CmsSnippet.new
  render action: 'edit'
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/manage/cms_snippets_controller.rb', line 25

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