Class: Cmtool::DirectoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/cmtool/directories_controller.rb

Instance Method Summary collapse

Methods included from ControllerGlue

#cmtool_user

Instance Method Details

#createObject

POST /directories POST /directories.xml



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/cmtool/directories_controller.rb', line 43

def create
  @directory = Cmtool::Directory.new(directory_params)

  respond_to do |format|
    if @directory.save
      format.html { redirect_to([cmtool, @directory], :notice => I18n.t('cmtool.action.create.successful', :model => Cmtool::Directory.model_name.human)) }
      format.xml  { render :xml => @directory, :status => :created, :location => @directory }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @directory.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /directories/1 DELETE /directories/1.xml



75
76
77
78
79
80
81
82
83
# File 'app/controllers/cmtool/directories_controller.rb', line 75

def destroy
  @directory = Cmtool::Directory.find(params[:id])
  @directory.destroy
  flash[:notice] = I18n.t('cmtool.action.destroy.successful', :model => Cmtool::Directory.model_name.human)
  respond_to do |format|
    format.html { redirect_to(cmtool.directories_url) }
    format.xml  { head :ok }
  end
end

#directory_paramsObject



90
91
92
# File 'app/controllers/cmtool/directories_controller.rb', line 90

def directory_params
  params.require(:directory).permit(:name, :parent_id)
end

#editObject

GET /directories/1/edit



37
38
39
# File 'app/controllers/cmtool/directories_controller.rb', line 37

def edit
  @directory = Cmtool::Directory.find(params[:id])
end

#indexObject

GET /directories GET /directories.xml



5
6
7
8
9
10
11
12
# File 'app/controllers/cmtool/directories_controller.rb', line 5

def index
  @directories = Cmtool::Directory.roots

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @directories }
  end
end

#newObject

GET /directories/new GET /directories/new.xml



27
28
29
30
31
32
33
34
# File 'app/controllers/cmtool/directories_controller.rb', line 27

def new
  @directory = Cmtool::Directory.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @directory }
  end
end

#remove_imageObject



84
85
86
87
88
# File 'app/controllers/cmtool/directories_controller.rb', line 84

def remove_image
  @directory = Cmtool::Directory.find(params[:id])
  @directory.image = nil
  @directory.save
end

#showObject

GET /directories/1 GET /directories/1.xml



16
17
18
19
20
21
22
23
# File 'app/controllers/cmtool/directories_controller.rb', line 16

def show
  @directory = Cmtool::Directory.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @directory }
  end
end

#updateObject

PUT /directories/1 PUT /directories/1.xml



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/cmtool/directories_controller.rb', line 59

def update
  @directory = Cmtool::Directory.find(params[:id])

  respond_to do |format|
    if @directory.update_attributes(directory_params)
      format.html { redirect_to([cmtool, @directory], :notice => I18n.t('cmtool.action.update.successful', :model => Cmtool::Directory.model_name.human)) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @directory.errors, :status => :unprocessable_entity }
    end
  end
end