Class: Editor::EventsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ApplicationController
- Editor::EventsController
- Defined in:
- app/controllers/editor/events_controller.rb
Overview
This controller manage Event model for editors
Instance Method Summary collapse
-
#create ⇒ Object
POST /editor/events.
-
#destroy ⇒ Object
DELETE /editor/events/:id.
-
#edit ⇒ Object
GET /editor/events/:id/edit.
-
#event_params ⇒ Object
private
Filter params for set a Event.
-
#filter_params ⇒ Object
private
Filter params for search a Event.
-
#index ⇒ Object
GET /editor/events.
-
#new ⇒ Object
GET /editor/events/new.
-
#set_event ⇒ Object
private
set @event for current user when needed.
- #set_groups ⇒ Object private
-
#show ⇒ Object
GET /editor/events/:id.
-
#update ⇒ Object
PATCH/PUT /editor/events/:id.
Methods inherited from ApplicationController
Methods inherited from ApplicationController
#access_denied!, #default_url_options, #record_not_found!, #set_turbo, #switch_locale
Instance Method Details
#create ⇒ Object
POST /editor/events
31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/editor/events_controller.rb', line 31 def create @event = Event.new(event_params) if @event.save @status = { success: "Evento creato" } redirect_to editor_event_path(@event) else @status = { error: "ERRORE - Evento non creato. Verifica gli errori." } render action: :new end end |
#destroy ⇒ Object
DELETE /editor/events/:id
54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/editor/events_controller.rb', line 54 def destroy if @event.destroy @status = { success: "Evento eliminato" } redirect_to editor_events_path else @status = { error: "ERRORE - Evento non eliminato. Verifica gli errori." } render action: :edit end end |
#edit ⇒ Object
GET /editor/events/:id/edit
28 |
# File 'app/controllers/editor/events_controller.rb', line 28 def edit; end |
#event_params ⇒ Object (private)
Filter params for set a Event
82 83 84 85 |
# File 'app/controllers/editor/events_controller.rb', line 82 def event_params params.require(:event).permit(:tickets_frequency, :title, :group_id, :body, :start_on, :stop_on, :pinned, :image, :where) end |
#filter_params ⇒ Object (private)
Filter params for search a Event
77 78 79 |
# File 'app/controllers/editor/events_controller.rb', line 77 def filter_params params.fetch(:filter, {}).permit(:category, :from, :text, :to) end |
#index ⇒ Object
GET /editor/events
10 11 12 13 14 15 16 17 |
# File 'app/controllers/editor/events_controller.rb', line 10 def index @categories = @groups.pluck :title, :id from = filter_params[:from] to = filter_params[:to] group_id = @groups.exists?(filter_params[:category]) ? filter_params[:category] : @groups.pluck(:id) text = filter_params[:text] @pagy, @events = pagy(Event.searchable(from:, to:, group_id:, text:), items: 6) end |
#new ⇒ Object
GET /editor/events/new
23 24 25 |
# File 'app/controllers/editor/events_controller.rb', line 23 def new @event = Event.new end |
#set_event ⇒ Object (private)
set @event for current user when needed
67 68 69 70 |
# File 'app/controllers/editor/events_controller.rb', line 67 def set_event @event = Event.find_by(id: params[:id], group: @groups) @scope = @event.id end |
#set_groups ⇒ Object (private)
72 73 74 |
# File 'app/controllers/editor/events_controller.rb', line 72 def set_groups @groups = current_user.groups end |
#show ⇒ Object
GET /editor/events/:id
20 |
# File 'app/controllers/editor/events_controller.rb', line 20 def show; end |
#update ⇒ Object
PATCH/PUT /editor/events/:id
43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/editor/events_controller.rb', line 43 def update if @event.update(event_params) @status = { success: "Evento Aggiornato" } render action: :show else @status = { error: "ERRORE - Evento non aggiornato. Verifica gli errori." } render :edit end end |