Implement deletion of conferences

This commit is contained in:
Petko Bordjukov 2014-10-14 23:55:17 +03:00
parent ac5b1e2d4d
commit 845eb891b1
6 changed files with 21 additions and 10 deletions

View File

@ -1,11 +1,11 @@
module Management module Management
class ConferencesController < ManagementController class ConferencesController < ManagementController
before_action :assign_conference, only: [:edit, :update, :open_call_for_papers, :close_call_for_papers] before_action :assign_conference, only: [:edit, :update, :show, :destroy, :open_call_for_papers, :close_call_for_papers]
before_action :assign_conferences, only: [:index, :open_call_for_papers, :close_call_for_papers] before_action :assign_conferences, only: [:index, :destroy, :open_call_for_papers, :close_call_for_papers]
def new def new
@conference = Conference.new @conference = Conference.new
3.times { @conference.tracks.build } @conference.tracks.build(name: 'Track 1')
@conference.halls.build(name: 'Hall 1') @conference.halls.build(name: 'Hall 1')
end end
@ -27,6 +27,15 @@ module Management
def index def index
end end
def show
end
def destroy
@conference.destroy
render 'reload_table'
end
def open_call_for_papers def open_call_for_papers
@conference.call_for_papers_open = true @conference.call_for_papers_open = true
@conference.save @conference.save

View File

@ -8,12 +8,12 @@ class Conference < ActiveRecord::Base
translates :title, :description translates :title, :description
has_many :tracks, -> { order('id asc') } has_many :tracks, -> { order('id asc') }, dependent: :destroy
has_many :events, through: :tracks has_many :events, through: :tracks
has_many :candidate_speakers, through: :events has_many :candidate_speakers, through: :events
has_many :halls has_many :halls, dependent: :destroy
accepts_nested_attributes_for :tracks, :halls, allow_destroy: true accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') } scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') }

View File

@ -1,4 +1,6 @@
class Hall < ActiveRecord::Base class Hall < ActiveRecord::Base
belongs_to :conference belongs_to :conference
has_many :slots, dependent: :destroy has_many :slots, dependent: :destroy
validates :name, presence: true
end end

View File

@ -1,6 +1,6 @@
class Track < ActiveRecord::Base class Track < ActiveRecord::Base
belongs_to :conference belongs_to :conference
has_many :events has_many :events, dependent: :destroy
validates :name, presence: true validates :name, presence: true
validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i} validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i}

View File

@ -17,5 +17,5 @@ tr
= fa_icon :eye = fa_icon :eye
= link_to edit_management_conference_path(conference), title: t('actions.edit.button', model: Conference.model_name.human), class: 'btn btn-primary' = link_to edit_management_conference_path(conference), title: t('actions.edit.button', model: Conference.model_name.human), class: 'btn btn-primary'
= fa_icon :edit = fa_icon :edit
= link_to management_conference_path(conference), title: t('actions.destroy.button', model: Conference.model_name.human), class: 'btn btn-danger', method: :delete, data: {confirm: t('actions.are_you_sure')} = link_to management_conference_path(conference), title: t('actions.destroy.button', model: Conference.model_name.human), class: ['btn', 'btn-danger', conference.events.any? ? 'disabled' : nil], remote: true, method: :delete, data: {confirm: t('actions.are_you_sure')}
= fa_icon :trash = fa_icon :trash

View File

@ -1,6 +1,6 @@
div#halls div#halls
= form.simple_fields_for :halls do |ff| = form.simple_fields_for :halls do |ff|
.col-md-3 .col-md-4
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
.panel-title .panel-title
@ -9,7 +9,7 @@ div#halls
span.clearfix span.clearfix
.panel-body .panel-body
= ff.input :name = ff.input :name
.col-md-3 .col-md-4
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
.panel-title .panel-title