require 'differ' class ModerationsController < ApplicationController before_filter :authenticate_user! before_action :set_event, only: [:show, :edit, :update, :destroy] before_filter :set_mailer_host, only: [:update, :destroy] def index @events = Event.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) # Send an update mail to its author ModerationMailer.update(@event, current_user).deliver 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.require(:event).permit(: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.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 # Useful to manage absolute url in mails def set_mailer_host ActionMailer::Base.default_url_options[:host] = request.host_with_port end end