Skip to content

Commit

Permalink
add delete option for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
lisbethmarianne committed Oct 9, 2015
1 parent d6e4ec3 commit 8f78240
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class EventsController < ApplicationController
http_basic_authenticate_with name: ENV['DT_USERNAME'], password: ENV['DT_PASSWORD'], only: [:admin_index, :admin_show, :edit]
before_action :get_event, only: [:admin_show, :edit, :update]
before_action :get_event, only: [:admin_show, :edit, :update, :destroy]

def index
@events = Event.approved
Expand Down Expand Up @@ -46,6 +46,11 @@ def update
end
end

def destroy
@event.destroy
redirect_to admin_url
end

private
def event_params
params.require(:event).permit(:organizer_name, :organizer_email, :organizer_email_confirmation, :description, :name, :start_date, :end_date, :question_1, :question_2, :question_3, :approved)
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Event < ActiveRecord::Base
has_many :applications
has_many :applications, dependent: :destroy

validates :organizer_name, :description, :name, presence: true
validates :start_date, date: true
Expand Down
10 changes: 5 additions & 5 deletions app/views/events/admin_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<% @events.each do |event| %>
<p>
<%= link_to event.name, event_admin_path(:id => event.id) %>
<% if event.approved %>
<%= link_to 'Unapprove', edit_event_path(:id => event.id) %>
<% else %>
<%= link_to 'Approve', edit_event_path(:id => event.id) %>
<% end %>
<%= link_to 'Download CSV', event_admin_path(:id => event.id, :format => :csv) %>
<%= link_to 'Edit', edit_event_path(:id => event.id) %>
<%= link_to 'Delete', url_for(action: :destroy, id: event.id), method: :delete, data: { confirm: "Are you sure?" } %>
</p>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
resources :events, except: [:destroy] do
resources :events do
resources :applications, only: [:show, :new, :create]
end

Expand Down

0 comments on commit 8f78240

Please sign in to comment.