| Class | Admin::TreesController |
| In: |
app/controllers/admin/trees_controller.rb
|
| Parent: | Admin::BaseController |
Controlador para la administración de árboles de categorías
Creación de un árbol
# File app/controllers/admin/trees_controller.rb, line 49
49: def create
50: @tree = Tree.new(params[:tree])
51: set_current_tab
52: respond_to do |format|
53: if @tree.save
54: flash[:notice] = 'Tree was successfully created.'
55: format.html { redirect_to(admin_tree_url(@tree)) }
56: format.xml { render :xml => @tree, :status => :created, :location => @tree }
57: else
58: format.html { render :action => "new" }
59: format.xml { render :xml => @tree.errors, :status => :unprocessable_entity }
60: end
61: end
62: end
Eliminar un árbol
# File app/controllers/admin/trees_controller.rb, line 82
82: def destroy
83: @tree = Tree.find(params[:id])
84: @tree.destroy
85: set_current_tab
86:
87: respond_to do |format|
88: format.html { redirect_to(admin_trees_url) }
89: format.xml { head :ok }
90: end
91: end
Modificar un árbol
# File app/controllers/admin/trees_controller.rb, line 42
42: def edit
43: @tree = Tree.find(params[:id])
44: @title = "Modificar #{@tree.name_es}"
45: set_current_tab
46: end
Listado de árboles
# File app/controllers/admin/trees_controller.rb, line 9
9: def index
10: @trees = Tree.find(:all)
11: @title = 'Categorías'
12: set_current_tab
13: respond_to do |format|
14: format.html # index.html.erb
15: format.xml { render :xml => @trees }
16: end
17: end
Formulario de nuevo árbol
# File app/controllers/admin/trees_controller.rb, line 31
31: def new
32: @tree = Tree.new
33: @title = 'Nueva sección'
34: set_current_tab
35: respond_to do |format|
36: format.html # new.html.erb
37: format.xml { render :xml => @tree }
38: end
39: end
Vista de un árbol
# File app/controllers/admin/trees_controller.rb, line 20
20: def show
21: @tree = Tree.find(params[:id])
22: @title = "#{@tree.name_es} / #{@tree.name_eu}"
23: set_current_tab
24: respond_to do |format|
25: format.html # show.html.erb
26: format.xml { render :xml => @tree }
27: end
28: end
Actualizar un árbol
# File app/controllers/admin/trees_controller.rb, line 65
65: def update
66: @tree = Tree.find(params[:id])
67: set_current_tab
68:
69: respond_to do |format|
70: if @tree.update_attributes(params[:tree])
71: flash[:notice] = 'Tree was successfully updated.'
72: format.html { redirect_to(admin_tree_url(@tree)) }
73: format.xml { head :ok }
74: else
75: format.html { render :action => "edit" }
76: format.xml { render :xml => @tree.errors, :status => :unprocessable_entity }
77: end
78: end
79: end