Commit 102338bc0f6f766e5e7df1ea050503ceeb4ff891
1 parent
4467d7c0
Exists in
master
and in
29 other branches
ActionItem4: basic managing tags
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@36 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
80 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +class ManageTagsController < ApplicationController | ||
2 | + def index | ||
3 | + list | ||
4 | + render :action => 'list' | ||
5 | + end | ||
6 | + | ||
7 | + def list | ||
8 | + @tags = Tag.find_all | ||
9 | + end | ||
10 | + | ||
11 | + def new | ||
12 | + @tags = Tag.find_all | ||
13 | + @tag = Tag.new | ||
14 | + end | ||
15 | + | ||
16 | + def create | ||
17 | + @tag = Tag.new | ||
18 | + @tag.name = params[:tag][:name] | ||
19 | + @tag.parent = Tag.find(params[:parent_id].to_i) if params[:parent_id] != "0" | ||
20 | + if @tag.save | ||
21 | + flash[:notice] = _('Tag was successfully created.') | ||
22 | + redirect_to :action => 'list' | ||
23 | + else | ||
24 | + render :action => 'new' | ||
25 | + end | ||
26 | + end | ||
27 | +end |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +class ActsAsTaggableMigration < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :tags do |t| | ||
4 | + t.column :name, :string | ||
5 | + t.column :parent_id, :integer | ||
6 | + end | ||
7 | + | ||
8 | + create_table :taggings do |t| | ||
9 | + t.column :tag_id, :integer | ||
10 | + t.column :taggable_id, :integer | ||
11 | + | ||
12 | + # You should make sure that the column created is | ||
13 | + # long enough to store the required class names. | ||
14 | + t.column :taggable_type, :string | ||
15 | + | ||
16 | + t.column :created_at, :datetime | ||
17 | + end | ||
18 | + | ||
19 | + add_index :taggings, :tag_id | ||
20 | + add_index :taggings, [:taggable_id, :taggable_type] | ||
21 | + end | ||
22 | + | ||
23 | + def self.down | ||
24 | + drop_table :taggings | ||
25 | + drop_table :tags | ||
26 | + end | ||
27 | +end |