ensl.org/app/controllers/directories_controller.rb

62 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

class DirectoriesController < ApplicationController
2014-03-31 21:33:16 +00:00
before_filter :get_directory, except: [:new, :create]
def show
if @directory.hidden
@files = @directory.files
2014-03-31 21:33:16 +00:00
render partial: 'data_files/list', layout: true
else
2014-03-31 21:33:16 +00:00
@directories = Directory.ordered.filtered.all conditions: { parent_id: 1 }
end
end
def new
@directory = Directory.new
@directory.parent = Directory.find params[:id]
raise AccessError unless @directory.can_create? cuser
end
def edit
raise AccessError unless @directory.can_update? cuser
end
def refresh
@directory.process_dir
2014-03-31 21:33:16 +00:00
render text: t(:directories_update)
end
def create
@directory = Directory.new params[:directory]
raise AccessError unless @directory.can_create? cuser
if @directory.save
flash[:notice] = t(:directories_create)
redirect_to(@directory)
else
2014-03-31 21:33:16 +00:00
render :new
end
end
def update
raise AccessError unless @directory.can_update? cuser
if @directory.update_attributes(params[:directory])
flash[:notice] = t(:directories_update)
redirect_to @directory
else
2014-03-31 21:33:16 +00:00
render :edit
end
end
def destroy
raise AccessError unless @directory.can_destroy? cuser
@directory.destroy
redirect_to directories_url
end
private
def get_directory
@directory = Directory.find params[:id]
end
end