Skip to content

Instantly share code, notes, and snippets.

@joebrislin
Created December 10, 2015 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebrislin/4371636194572dc8f5b2 to your computer and use it in GitHub Desktop.
Save joebrislin/4371636194572dc8f5b2 to your computer and use it in GitHub Desktop.
Code Samples - Case Studies Extension for Marketing Website (Refinery CMS)
module Refinery
module Casestudies
class CasestudiesController < ::ApplicationController
layout :selectLayout
before_action :find_all_casestudies
before_action :find_page
def index
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @casestudy in the line below:
present(@page)
end
def show
@casestudy = Casestudy.friendly.find(params[:id])
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @casestudy in the line below:
# Takes the view template from the select box in the admin view
# and sets the view to that if there is one.
viewToRender = @casestudy.template_view.to_s
if(viewToRender != ("").to_s)
render action: viewToRender.downcase
end
present(@page)
end
protected
def find_all_casestudies
@casestudies = Casestudy.order('position ASC')
end
def find_page
@page = ::Refinery::Page.where(:link_url => "/casestudies").first
end
# Selects Fluid vs Non-Fluid Layout based on CS Design
def selectLayout
# Currently the only case is the nTelos CS
if(params[:id].to_s == "ntelos-wireless" || params[:id].to_s == "ntelos")
"fluid"
else
"application"
end
end
end
end
end
module Refinery
module Casestudies
class Casestudy < Refinery::Core::BaseModel
extend FriendlyId
friendly_id :title, :use => [:slugged]
self.table_name = 'refinery_casestudies'
validates :title, :presence => true, :uniqueness => true
belongs_to :ctaimage, :class_name => '::Refinery::Image', :foreign_key => :ctaimage_id
belongs_to :ctahalfimage, :class_name => '::Refinery::Image', :foreign_key => :cta_half_image_id
belongs_to :ourworkimage, :class_name => '::Refinery::Image', :foreign_key => :ourwork_image_id
belongs_to :worklistimage, :class_name => '::Refinery::Image', :foreign_key => :worklist_image_id
belongs_to :excerpt, :class_name => '::Refinery::Resource'
belongs_to :fullcasestudy, :class_name => '::Refinery::Resource'
# To enable admin searching, add acts_as_indexed on searchable fields, for example:
#
# acts_as_indexed :fields => [:title]
end
end
end
<% if @casestudy.css.present? && @casestudy.css.length > 0 %>
<% @output_styles = capture do %>
<style type="text/css">
<%= raw @casestudy.css %>
</style>
<% end %>
<% end %>
<% content_for :body do %>
<%=raw @casestudy.body %>
<% end %>
<%= render '/refinery/content_page', :hide_sections => [:body_content_title] %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment