Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow commenting on Pitches and Tips
- Loading branch information
GIT_AUTHOR_NAME
committed
Dec 10, 2008
1 parent
f0bc3ab
commit 202c833
Showing
17 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class CommentsController < ApplicationController | ||
before_filter :login_required | ||
|
||
resources_controller_for :comments, :only => [:create] | ||
|
||
response_for :create do |format| | ||
format.html do | ||
if resource_saved? | ||
flash[:notice] = "Successfully created comment" | ||
redirect_to :back | ||
else | ||
render :action => :new | ||
end | ||
end | ||
end | ||
|
||
protected | ||
def new_resource | ||
returning resource_service.new(params[resource_name]) do |resource| | ||
resource.user = current_user | ||
end | ||
end | ||
|
||
def resource_service | ||
if enclosing_resource | ||
enclosing_resource.comments | ||
else | ||
Comment | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CommentsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Comment < ActiveRecord::Base | ||
belongs_to :commentable, :polymorphic => true | ||
belongs_to :user | ||
|
||
validates_presence_of :title, :body | ||
validates_length_of :body, :maximum => 2000 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.row | ||
= f.label :title | ||
= f.text_field :title | ||
.row | ||
= f.label :body | ||
= fckeditor_textarea('comment', 'body', :toolbarSet => 'Spotus', :height => '200px') | ||
.row | ||
= f.submit 'Post Comment' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.comment | ||
%h5= comment.title | ||
.avatar | ||
= image_tag comment.user.photo.url(:thumb) | ||
.body | ||
= comment.body | ||
%p.attribution | ||
by | ||
%span= comment.user.full_name | ||
on | ||
%span= comment.created_at.to_s(:long) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateComments < ActiveRecord::Migration | ||
def self.up | ||
create_table :comments do |t| | ||
t.string :title, :commentable_type | ||
t.integer :commentable_id | ||
t.belongs_to :user | ||
t.text :body | ||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :comments | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe CommentsController do | ||
describe "POST to create" do | ||
before do | ||
post :create, :comment => {:foo => 'bar'}, :pitch_id => 1 | ||
end | ||
it_denies_access | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe Comment do | ||
table_has_columns(Comment, :string, "commentable_type") | ||
table_has_columns(Comment, :string, "title") | ||
table_has_columns(Comment, :integer, "commentable_id") | ||
table_has_columns(Comment, :integer, "user_id") | ||
table_has_columns(Comment, :text, "body") | ||
|
||
requires_presence_of Comment, :body | ||
requires_presence_of Comment, :title | ||
|
||
it { Factory(:comment).should belong_to(:commentable) } | ||
|
||
it "should not be valid if body length is greater than 2000" do | ||
comment = Factory(:comment) | ||
comment.body = 'f' * 2001 | ||
comment.save | ||
comment.errors_on(:body).should_not be_nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters