From c2a63906deef02eee63f1befccf9dc68a5afce86 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 9 Jul 2007 19:06:09 +0000 Subject: [PATCH] ActionItem4: Added edit and destroy tags --- app/controllers/manage_tags_controller.rb | 25 ++++++++++++++++++++++++- app/views/manage_tags/_form.rhtml | 3 +-- app/views/manage_tags/list.rhtml | 4 +--- app/views/manage_tags/new.rhtml | 3 ++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/controllers/manage_tags_controller.rb b/app/controllers/manage_tags_controller.rb index 97e9e55..7c69cae 100644 --- a/app/controllers/manage_tags_controller.rb +++ b/app/controllers/manage_tags_controller.rb @@ -9,7 +9,7 @@ class ManageTagsController < ApplicationController end def new - @tags = Tag.find_all + @parent_tags = Tag.find_all @tag = Tag.new end @@ -24,4 +24,27 @@ class ManageTagsController < ApplicationController render :action => 'new' end end + + def edit + @parent_tags = Tag.find_all + @tag = Tag.find(params[:id]) + end + + def update + @tag = Tag.find(params[:id]) + @tag.name = params[:tag][:name] + @tag.parent = params[:parent_id] != "0" ? Tag.find(params[:parent_id].to_i) : nil + if @tag.save + flash[:notice] = _('Tag was successfully updated.') + redirect_to :action => 'list' + else + render :action => 'edit' + end + end + + def destroy + @tag = Tag.find(params[:id]) + @tag.destroy + redirect_to :action => 'list' + end end diff --git a/app/views/manage_tags/_form.rhtml b/app/views/manage_tags/_form.rhtml index 2f9931a..3645947 100644 --- a/app/views/manage_tags/_form.rhtml +++ b/app/views/manage_tags/_form.rhtml @@ -1,3 +1,2 @@ - Name: <%= text_field 'tag', 'name' %>
-Parent tag: <%= select_tag 'parent_id', [''] + @tags.map {|n|"'} %>
+Parent tag: <%= select_tag 'parent_id', [''] + @parent_tags.select{|pt| !pt.ancestors.include?(@tag) and pt != @tag}.map {|n|"'} %>
diff --git a/app/views/manage_tags/list.rhtml b/app/views/manage_tags/list.rhtml index 4ab2e35..4c38493 100644 --- a/app/views/manage_tags/list.rhtml +++ b/app/views/manage_tags/list.rhtml @@ -1,9 +1,7 @@

<%= _("Listing tags") %>

<%= link_to _('New tag'), {:action => 'new'} %> diff --git a/app/views/manage_tags/new.rhtml b/app/views/manage_tags/new.rhtml index 9ab7dbf..8444f4c 100644 --- a/app/views/manage_tags/new.rhtml +++ b/app/views/manage_tags/new.rhtml @@ -2,5 +2,6 @@ <%= start_form_tag :action =>'create' %> <%= render :partial => 'form' %> - <%= submit_tag 'Create' %> + <%= submit_tag _('Create') %> + <%= link_to _('Cancel'), {:action => 'list'} %> <%= end_form_tag %> -- libgit2 0.21.2