Browse Source

Create comment model and database schema

* New Comment model
* New migration
master
Peter J. Jones 11 years ago
parent
commit
51e477be23
4 changed files with 99 additions and 0 deletions
  1. 4
    0
      README
  2. 43
    0
      app/models/comment.rb
  3. 28
    0
      db/migrate/001_create_initial_schema.rb
  4. 24
    0
      init.rb

+ 4
- 0
README View File

@@ -0,0 +1,4 @@
= Banter

Banter is a plugin for Ruby on Rails that provides commenting
abilities. It is implemented as a Rails Engine.

+ 43
- 0
app/models/comment.rb View File

@@ -0,0 +1,43 @@
################################################################################
#
# Copyright (C) 2008 pmade inc. (Peter Jones pjones@pmade.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
class Comment < ActiveRecord::Base

################################################################################
validates_presences_of(:content)
################################################################################
belongs_to(:banter, :polymorphic => true)
has_many(:replies, :class_name => 'Comment', :foreign_key => 'reply_id')
################################################################################
private
################################################################################
before_save do |comment|
# Cache the contents as HTML
comment.content_cache = RedCloth.new(comment.content).to_html
end
end

+ 28
- 0
db/migrate/001_create_initial_schema.rb View File

@@ -0,0 +1,28 @@
################################################################################
class CreateInitialSchema < ActiveRecord::Migration
################################################################################
def self.up
create_table(:comments) do |t|
t.column(:banter_id, :integer)
t.column(:banter_type, :string)
t.column(:user_id, :integer)
t.column(:reply_id, :integer)
t.column(:author_name, :string, :default => 'Anonymous')
t.column(:author_email, :string)
t.column(:author_url, :string)
t.column(:wants_replies, :boolean, :default => false)
t.column(:was_edited, :boolean, :default => false)
t.column(:content, :text)
t.column(:content_cache, :text)
t.column(:created_at, :datetime)
t.column(:updated_at, :datetime)
end
end
################################################################################
def self.down
drop_table(:comments)
end
end

+ 24
- 0
init.rb View File

@@ -0,0 +1,24 @@
################################################################################
#
# Copyright (C) 2008 pmade inc. (Peter Jones pjones@pmade.com)
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################

Loading…
Cancel
Save