agenda-libre-ruby/app/controllers/moderations_controller.rb

49 lines
1.5 KiB
Ruby

class ModerationsController < InheritedResources::Base
before_filter :authenticate_user!
before_action :set_event, only: [:show, :edit, :update, :destroy]
def index
@events = Event.unscoped.where moderated: 0
end
# PATCH/PUT /moderations/1
# PATCH/PUT /moderations/1.json
def update
# This is a special case, required to handle the region attribute with same foreign key name
@event.region = Region.find(params[:event][:region])
if params[:visu]
@event.attributes = event_params
render action: 'edit'
return
end
respond_to do |format|
if @event.update(event_params)
format.html { redirect_to moderations_path, notice: 'Event was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
private
def permitted_params
params.permit event: [:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags]
end
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.unscoped.find params[:id]
@moderation = @event
end
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags
end
end