Created
June 19, 2015 15:56
-
-
Save banister/790c6759f164a8267674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CircuitsController < ApplicationController | |
layout 'circuit_landing_page' | |
skip_before_filter :authenticate_user! | |
before_filter :set_programs, only: :show | |
respond_to :html | |
CIRCUIT_PROGRAM_IDS = { | |
'web-design-circuit' => 3689, | |
'data-analysis-circuit' => 4105 | |
} | |
def show | |
@cwe_instances = @cwe_program.instances.published.select(&:display_in_listing?).sort_by(&:starts) | |
@instances = @program.instances.published.select(&:display_in_listing?).sort_by(&:starts) | |
@online_metro = Metro.find_by_name "Online" | |
set_program_metas(@program, circuit_landing_page_url(slug: @program.slug), @program.meta_data.try(:[], 'title')) | |
render template: "circuits/#{template_name}" | |
end | |
def enroll | |
# NOTE: Because of the hacky way we are currently doing Circuits | |
# self-enrollment, we do not want to capture the cwe instance id | |
# on the lead and would prefer to just capture the correct program. | |
# (Max 05/29/15) | |
@lead = Lead.new(params[:lead].except(:cwe_instance_id)) | |
if @lead.save | |
redirect_to instance_landing_page_path(params[:lead][:program_id], 'online', params[:lead][:cwe_instance_id]) | |
else | |
redirect_to :back, notice: "Hey, sorry something went wrong. :( Try again." | |
end | |
end | |
private | |
def set_programs | |
@program = Program.friendly.find(params[:slug]) || not_found | |
@cwe_program = Program.find(CIRCUIT_PROGRAM_IDS[@program.slug]) | |
end | |
def template_name | |
if @program.landing_page_template.present? | |
@program.landing_page_template | |
else | |
@program.title.parameterize('_') | |
end | |
end | |
def set_program_metas(program, canonical, title=nil) | |
set_metas( | |
title: title || "#{program.title} | #{program.domains.first} #{program.format.titleize}", | |
description: (program.meta_data.present? ? program.meta_data['description'] : nil) || program.overview, | |
og_title: program.title, | |
og_image: program.default_image.url, | |
twitter_title: program.title, | |
twitter_description: program.overview, | |
twitter_image: program.default_image.url, | |
canonical: canonical | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment