Skip to content

Instantly share code, notes, and snippets.

@sibsfinx
Last active February 7, 2019 11:10
Show Gist options
  • Save sibsfinx/0ba0af04c83d11ed3d6446c6edf30991 to your computer and use it in GitHub Desktop.
Save sibsfinx/0ba0af04c83d11ed3d6446c6edf30991 to your computer and use it in GitHub Desktop.
code example: ruby on rails

Content website, 2014–2016

ruby on rails, haml, sass, coffescript, jquery

dokku/docker -> ansible + capistrano

class Course < ActiveRecord::Base
include FriendlyId
include Bootsy::Container
validates :title, :publicated_at, presence: true
before_validation :set_publicated_at
has_and_belongs_to_many :cities
belongs_to :language
belongs_to :lead_form
has_many :custom_properties, as: :entity, dependent: :destroy
accepts_nested_attributes_for :custom_properties, allow_destroy: true
friendly_id :title, use: [:slugged, :finders, :history]
mount_uploader :image, CourseImageUploader
#paginates_per 10
scope :active, -> { where("publicated_at <= ? AND active = ?", "#{Time.zone.now}", true).order('position ASC') }
scope :is_navigation, -> { where(is_navigation: true) }
scope :active_with_languages, -> { active.where("language_id is not null") }
scope :by_city, -> (city) { joins(:cities).where('city_id = ?', city.id) }
def active?
publicated_at < Time.zone.now && active == true
end
def to_s
"#{title}"
end
def ordered_properties
self.custom_properties.order('position ASC')
end
def should_generate_new_friendly_id?
title_changed? or slug.nil? or slug.blank?
end
def normalize_friendly_id(input)
input.to_s.to_slug.normalize(transliterations: :russian).to_s
end
private
def set_publicated_at
self.publicated_at = Time.zone.now unless publicated_at.present?
end
end
window.LeadForm ||= {}
((app) ->
$(document).ready ->
$findFormBtn = $('@landing-teaser--find-form-btn')
$formBlock = $('@landing-teaser--form-block')
$form = $formBlock.find('[role*="landing-teaser--form"]')
$formEl = $formBlock.find('[role*="landing-teaser--form-element"]')
$submitBtn = $formBlock.find('[role*="landing-teaser--form-submit-btn"]')
$errorBlock = $formBlock.find('[role*="landing-teaser--form-error"]')
$successBlock = $formBlock.find('[role*="landing-teaser--form-success"]')
$findFormBtn.on 'click', (e) ->
formTop = $formBlock.offset().top - $formBlock.height()/2
$('body').animate({
scrollTop: formTop
}, 300)
$formEl
.on 'ajax:beforeSend', (e) ->
goal_code = $(@).data 'goal_code'
ya_params =
goal_code: goal_code
if ga?
ga 'send', 'event', 'lead_form', goal_code
if yaCounter9611713?
yaCounter9611713.reachGoal "LEAD_FORM", ya_params
.on 'ajax:success', (e, data, status, xhr) ->
handleSuccess $form, $successBlock, $errorBlock
.on 'ajax:error', (e, data, status, xhr) ->
handleError $form, $successBlock, $errorBlock
handleError = ($form, $successBlock, $errorBlock) ->
$successBlock.removeClass('animated fadeIn').addClass('animated fadeOut hide')
$errorBlock.removeClass('animated fadeOut hide').addClass('animated fadeIn')
#$form.addClass('animated fadeOut hide')
handleSuccess = ($form, $successBlock, $errorBlock) ->
$errorBlock.removeClass('animated fadeIn').addClass('animated fadeOut hide')
$form.addClass('animated fadeOut hide')
$successBlock.removeClass('animated fadeOut hide').addClass('animated fadeIn')
)(window.LeadForm ||= {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment