adding tags to page models

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@33 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2007-11-17 06:13:45 +00:00
parent f3940be586
commit 07aa98e94f
7 changed files with 41 additions and 2 deletions

View File

@ -12,6 +12,7 @@
#
class Page < ActiveRecord::Base
acts_as_versioned
acts_as_taggable
belongs_to :owner, :polymorphic => true
validates_presence_of :title

2
app/models/tag.rb Normal file
View File

@ -0,0 +1,2 @@
class Tag < ActiveRecord::Base
end

View File

@ -11,7 +11,7 @@
<%= @page.html %>
</div>
<ul class="meta">
<li>Add Tags here</li>
<li>Tags: <%= @page.tag_names.join(' ') -%></li>
<li>Version: <%= @page.version -%></li>
<% @page.owner.page_attributes.each do |x| -%>
<li><%= x -%></li>

View File

@ -1,3 +1,6 @@
<p>
<label for="page_redcloth">Description</label> <%= text_area 'page', 'redcloth' %>
</p>
</p>
<p>
<label for="page_tag_names">Tags</label> <%= text_field 'page', 'tag_names' %>
</p>

18
db/migrate/005_tags.rb Normal file
View File

@ -0,0 +1,18 @@
class Tags < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.column :name, :string
end
create_table :tags_pages, :id => false do |t|
t.column :tag_id, :integer
t.column :page_id, :integer
end
add_index :tags, :name
add_index :tags_pages, [ :tag_id, :page_id ]
end
def self.down
drop_table :tags
drop_table :tags_pages
end
end

5
test/fixtures/tags.yml vendored Normal file
View File

@ -0,0 +1,5 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
id: 1
two:
id: 2

10
test/unit/tag_test.rb Normal file
View File

@ -0,0 +1,10 @@
require File.dirname(__FILE__) + '/../test_helper'
class TagTest < Test::Unit::TestCase
fixtures :tags
# Replace this with your real tests.
def test_truth
assert true
end
end