Suppression de InheritedResource

This commit is contained in:
echarp 2014-06-22 22:06:12 +02:00
parent cc2ed4ee89
commit c7a6f04489
2 changed files with 22 additions and 7 deletions

View File

@ -1,10 +1,10 @@
class EventsController < InheritedResources::Base class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :cancel, :destroy] before_action :set_event, only: [:show, :edit, :update, :cancel, :destroy]
before_action :check_secret, only: [:edit, :update, :cancel, :destroy] before_action :check_secret, only: [:edit, :update, :cancel, :destroy]
before_filter :set_mailer_host before_filter :set_mailer_host
def index def index
@events = Event @events = Event.moderated
if (params[:region] && params[:region].present? && params[:region] != 'all') if (params[:region] && params[:region].present? && params[:region] != 'all')
@events = @events.region(params[:region]) @events = @events.region(params[:region])
end end
@ -31,6 +31,11 @@ class EventsController < InheritedResources::Base
end end
end end
# GET /users/new
def new
@event = Event.new
end
# POST /events # POST /events
# POST /events.json # POST /events.json
def create def create
@ -84,18 +89,29 @@ class EventsController < InheritedResources::Base
end end
end end
# DELETE /events/1
# DELETE /events/1.json
def destroy
@event.destroy
respond_to do |format|
format.html { redirect_to events_url }
format.json { head :no_content }
end
end
private private
def permitted_params def permitted_params
params.permit event: [:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags] params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags)
end end
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_event def set_event
if (params[:secret].present?) if (params[:secret].present?)
@event = Event.unscoped.where(secret: params[:secret]).find(params[:id]) @event = Event.where(secret: params[:secret])
else else
@event = Event.find(params[:id]) @event = Event.moderated
end end
@event = @event.find(params[:id])
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.

View File

@ -9,8 +9,7 @@ class Event < ActiveRecord::Base
validates :submitter, email: true validates :submitter, email: true
default_scope { where moderated: 1 } scope :moderated, -> { where moderated: 1 }
scope :past, -> { where('end_time < now()').order(start_time: :desc) } scope :past, -> { where('end_time < now()').order(start_time: :desc) }
scope :future, -> { where('end_time >= now()').order(start_time: :asc) } scope :future, -> { where('end_time >= now()').order(start_time: :asc) }
scope :future_30, -> { scope :future_30, -> {