Module: Ecm::CalendarHelper::Controller::CalendarConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/concerns/ecm/calendar_helper/controller/calendar_concern.rb

Overview

Usage:

Add javascripts:

# app/assets/javascripts/application.js
//= require ecm_calendar_helper

Add stylesheets:

# app/assets/stylesheets/application.css
/*
 *= require ecm_calendar_helper
 */

Add routes:

# config/routes.rb
Rails.application.routes.draw do
  resources :calendars, only: [:index], constraints: ->(r) { r.xhr? } do
    get "(/:year/:month)", action: :index, on: :collection
  end
end

Add controller:

# app/controllers/calendars_controller.rb
class CalendarsController < ApplicationController
  include EcmCalendarHelper::Controller::CalendarConcern

  private

  def load_collection_for_calendar
    @collection = Posts.for_calendar.in_month(@date).all
  end
end

Add views:

Copy Ecm::CalendarHelper::Engine.root.join('app/views/ecm/calendar_helper/calendar_concern/*') => app/views/calendars/

Render the calendar somewhere in your views:

# app/views/*.html.haml
#calendar{ data: { calendar: calendars_url } }

Instance Method Summary collapse

Instance Method Details

#indexObject



61
62
63
64
65
66
67
# File 'app/concerns/ecm/calendar_helper/controller/calendar_concern.rb', line 61

def index
  if request.xhr?
    render layout: nil
  else
    render
  end
end