Controlador para la administración de árboles de categorías
Creación de un árbol
# File app/controllers/admin/trees_controller.rb, line 79 def create @tree = Tree.new(params[:tree]) set_current_tab respond_to do |format| if @tree.save flash[:notice] = 'Tree was successfully created.' format.html { redirect_to(admin_tree_url(@tree)) } format.xml { render :xml => @tree, :status => :created, :location => @tree } else format.html { render :action => "new" } format.xml { render :xml => @tree.errors, :status => :unprocessable_entity } end end end
Eliminar un árbol
# File app/controllers/admin/trees_controller.rb, line 112 def destroy @tree = Tree.find(params[:id]) @tree.destroy set_current_tab respond_to do |format| format.html { redirect_to(admin_trees_url) } format.xml { head :ok } end end
Modificar un árbol
# File app/controllers/admin/trees_controller.rb, line 63 def edit @tree = Tree.find(params[:id]) @title = "Modificar #{@tree.name_es}" set_current_tab respond_to do |format| format.html format.js { render :update do |page| page.replace_html "edit_container", :partial => 'edit' page[:name_es].focus end } end end
Listado de árboles
# File app/controllers/admin/trees_controller.rb, line 30 def index @trees = Tree.find(:all) @title = 'Categorías' set_current_tab respond_to do |format| format.html # index.html.erb format.xml { render :xml => @trees } end end
Formulario de nuevo árbol
# File app/controllers/admin/trees_controller.rb, line 52 def new @tree = Tree.new @title = 'Nueva sección' set_current_tab respond_to do |format| format.html # new.html.erb format.xml { render :xml => @tree } end end
Vista de un árbol
# File app/controllers/admin/trees_controller.rb, line 41 def show @tree = Tree.find(params[:id]) @title = "#{@tree.name_es} / #{@tree.name_eu}" set_current_tab respond_to do |format| format.html # show.html.erb format.xml { render :xml => @tree } end end
Actualizar un árbol
# File app/controllers/admin/trees_controller.rb, line 95 def update @tree = Tree.find(params[:id]) set_current_tab respond_to do |format| if @tree.update_attributes(params[:tree]) flash[:notice] = 'Tree was successfully updated.' format.html { redirect_to(admin_tree_url(@tree)) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @tree.errors, :status => :unprocessable_entity } end end end