Sha256: 7f39121479692a2cfae56b5aab0ccfd25b251e69bff958ff02ba159f698c5ce0

Contents?: true

Size: 1.87 KB

Versions: 9

Compression:

Stored size: 1.87 KB

Contents

module Hicube  
  class Public::PagesController < Public::BaseController

    skip_before_filter :verify_authenticity_token
    before_action :load_resource, except: [:mail]

    def show
      filename = "#{Rails.root}/tmp/#{@page}_#{Process.pid}.slim"
      
      f = File.new(filename, "w+")
      f.write ::Liquid::Template.parse(@page.body).render
      f.close

      @page_content = ::Slim::Template.new(filename).render(Object.new, 
        links: Hicube::Page.parents.map(&:slug), 
        header_links: Hicube::Page.parents.headers.map(&:slug),
        footer_links: Hicube::Page.parents.footers.map(&:slug),
        documents: Hicube::Document.all, id: @page.slug
      )
    rescue Exception => e
      logger.error "Error: Rendering #{@page} failed."
      logger.error e
    end

    def mail
      PageMailer.notify(page_params).deliver_now
      
      respond_to do |format|
        format.html {
          if params[:page].has_key?(:success_page)
            redirect_to "/#{params[:page][:success_page]}"
          else
            redirect_to :back, flash: {success: "Message Sent! We will be in touch shortly."}
          end
        }
        format.json { render json: 'Message sent!', status: 200}
      end
    rescue
      respond_to do |format|
        format.html { redirect_to :back }
        format.json { render json: page_params, status: :unprocessable_entity }
      end
    end

    def edit
      filename = "#{Rails.root}/tmp/#{@page}_#{Process.pid}.slim"
      
      f = File.new(filename, "w+")
      f.write ::Liquid::Template.parse(@page.body).render
      f.close

      @page_content = ::Slim::Template.new(filename).render Object.new, links: Hicube::Page.parents.map(&:slug), documents: Hicube::Document.all, id: @page.slug
  
    end

    private

    def page_params
      params.require(:page).permit(:subject, :name, :reply_to, :phone, :message)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hicube-0.0.9 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.8 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.7 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.6 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.5 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.4 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.3 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.2 app/controllers/hicube/public/pages_controller.rb
hicube-0.0.1 app/controllers/hicube/public/pages_controller.rb