Browse Source

Suppression de InheritedResource

recurrent
echarp 8 years ago
parent
commit
c7a6f04489
  1. 26
      app/controllers/events_controller.rb
  2. 3
      app/models/event.rb

26
app/controllers/events_controller.rb

@ -1,10 +1,10 @@
class EventsController < InheritedResources::Base
class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :cancel, :destroy]
before_action :check_secret, only: [:edit, :update, :cancel, :destroy]
before_filter :set_mailer_host
def index
@events = Event
@events = Event.moderated
if (params[:region] && params[:region].present? && params[:region] != 'all')
@events = @events.region(params[:region])
end
@ -31,6 +31,11 @@ class EventsController < InheritedResources::Base
end
end
# GET /users/new
def new
@event = Event.new
end
# POST /events
# POST /events.json
def create
@ -84,18 +89,29 @@ class EventsController < InheritedResources::Base
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
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
# Use callbacks to share common setup or constraints between actions.
def set_event
if (params[:secret].present?)
@event = Event.unscoped.where(secret: params[:secret]).find(params[:id])
@event = Event.where(secret: params[:secret])
else
@event = Event.find(params[:id])
@event = Event.moderated
end
@event = @event.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.

3
app/models/event.rb

@ -9,8 +9,7 @@ class Event < ActiveRecord::Base
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 :future, -> { where('end_time >= now()').order(start_time: :asc) }
scope :future_30, -> {

Loading…
Cancel
Save