osem-fcy/app/controllers/admin/tracks_controller.rb

60 lines
1.8 KiB
Ruby
Raw Normal View History

2014-08-06 21:14:00 +03:00
module Admin
class TracksController < Admin::BaseController
2014-08-12 11:51:59 +03:00
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program
2014-08-12 11:51:59 +03:00
def index; end
2013-01-07 09:04:09 +01:00
2014-08-06 21:14:00 +03:00
def show
respond_to do |format|
format.html { render }
2014-08-06 21:14:00 +03:00
format.json { render json: @conference.tracks.to_json }
end
end
2013-01-07 09:04:09 +01:00
def new
@track = @program.tracks.new
end
def create
@track = @program.tracks.new(track_params)
if @track.save
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully created.')
else
2014-11-30 15:41:47 +02:00
flash[:error] = "Creating Track failed: #{@track.errors.full_messages.join('. ')}."
render :new
end
end
def edit; end
2014-08-06 21:14:00 +03:00
def update
if @track.update_attributes(track_params)
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully updated.')
2014-08-06 21:14:00 +03:00
else
2014-11-30 15:41:47 +02:00
flash[:error] = "Track update failed: #{@track.errors.full_messages.join('. ')}."
render :edit
2014-08-06 21:14:00 +03:00
end
2013-01-07 09:04:09 +01:00
end
def destroy
if @track.destroy
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully deleted.')
else
redirect_to(admin_conference_program_tracks_path(conference_id: @conference.short_title),
error: "Track couldn't be deleted. #{@track.errors.full_messages.join('. ')}.")
end
end
private
def track_params
2015-10-28 18:05:15 +02:00
params.require(:track).permit(:name, :description, :color)
end
2013-01-07 09:04:09 +01:00
end
end