Class: Effective::EventsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::EventsController
- Includes:
- CrudController
- Defined in:
- app/controllers/effective/events_controller.rb
Instance Method Summary collapse
- #build_event_search ⇒ Object
- #event_category ⇒ Object
- #index ⇒ Object
- #search_params ⇒ Object
- #show ⇒ Object
Instance Method Details
#build_event_search ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/controllers/effective/events_controller.rb', line 46 def build_event_search search = EventSearch.new(search_params) search.current_user = current_user search.unpublished = EffectiveResources.(self, :admin, :effective_events) search.category ||= event_category search end |
#event_category ⇒ Object
54 55 56 57 |
# File 'app/controllers/effective/events_controller.rb', line 54 def event_category return nil unless params[:category].present? EffectiveEvents.categories.find { |category| category.parameterize == params[:category] } end |
#index ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/effective/events_controller.rb', line 10 def index @page_title ||= 'Events' EffectiveResources.(self, :index, Effective::Event) # Sometimes we just display a Datatable for the events @datatable = EffectiveResources.best('EffectiveEventsDatatable').new # But more often we do a full paginated index with search screen @event_search = build_event_search @event_search.search! @events = @event_search.results(page: params[:page]) end |
#search_params ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/effective/events_controller.rb', line 59 def search_params return {} unless params[:q].present? if params[:q].respond_to?(:to_h) # From the search form params.require(:q).permit! else { term: params.permit(:q).fetch(:q) } # From the url /events?q=asdf end end |
#show ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/effective/events_controller.rb', line 24 def show @event = resource_scope.find(params[:id]) @upcoming_events = resource_scope.upcoming.where.not(id: @event.id) if @event.respond_to?(:roles_permit?) raise Effective::AccessDenied.new('Access Denied', :show, @event) unless @event.roles_permit?(current_user) end EffectiveResources.(self, :show, @event) if EffectiveResources.(self, :admin, :effective_events) flash.now[:warning] = [ 'Hi Admin!', ('You are viewing a hidden event.' if @event.draft?), 'Click here to', ("<a href='#{effective_events.edit_admin_event_path(@event)}' class='alert-link'>edit event settings</a>.") ].compact.join(' ') end @page_title ||= @event.to_s end |