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

46 lines
1.4 KiB
Ruby
Raw Normal View History

2014-01-06 11:22:39 +01:00
class ModerationsController < InheritedResources::Base
before_filter :authenticate_user!
2014-01-06 11:22:39 +01:00
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
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