Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

parrot comments form partial

  • Loading branch information...
commit 151171a3483c07cea48a36238e45cc3acdaf45d1 1 parent ee3d416
@tute authored
View
1  .gitignore
@@ -3,4 +3,5 @@
.bundle
Gemfile.lock
rdoc
+test/dummy/log*
test/dummy/tmp
View
23 app/controllers/parrot/application_controller.rb
@@ -0,0 +1,23 @@
+module Parrot
+ class ApplicationController < ActionController::Base
+ def commentable_fk
+ commentable_fk = params.select{|k,v| k =~ /_id/ }.keys.first
+ end
+
+ def commentable_type
+ commentable_fk.gsub('_id', '')
+ end
+
+ def commentable_id
+ params[commentable_fk]
+ end
+
+ def commentable
+ commentable_type.capitalize.constantize.find(commentable_id)
+ end
+
+ def debug(object)
+ logger.warn "DEBUGGING: #{object.inspect}"
+ end
+ end
+end
View
20 app/controllers/parrot/comments_controller.rb
@@ -1,5 +1,5 @@
module Parrot
- class CommentsController < ActionController::Base
+ class CommentsController < ApplicationController
respond_to :html
def index
@@ -23,23 +23,5 @@ def create
@commentable_type = commentable_type
respond_with @comment, :location => commentable
end
-
- private
- def commentable_fk
- commentable_fk = params.select{|k,v| k =~ /_id/ }.keys.first
- end
- def commentable_type
- commentable_fk.gsub('_id', '')
- end
- def commentable_id
- params[commentable_fk]
- end
- def commentable
- commentable_type.capitalize.constantize.find(commentable_id)
- end
-
- def debug(object)
- logger.warn "DEBUGGING: #{object.inspect}"
- end
end
end
View
4 app/models/parrot/comment.rb
@@ -12,5 +12,9 @@ class Comment < ActiveRecord::Base
def self.following(other_comment)
where("created_at > '#{other_comment.created_at}'")
end
+
+ def author
+ Parrot.author_class.find(author_id)
+ end
end
end
View
3  app/views/parrot/comments/_comment.html.erb
@@ -1,2 +1 @@
-<%= comment.inspect %>
-<hr>
+<p><strong><%= comment.author %></strong>: <%= comment.body %></p>
View
22 app/views/parrot/comments/_form.html.erb
@@ -0,0 +1,22 @@
+<% @comment ||= Parrot::Comment.new %>
+<%= form_for([object, @comment]) do |f| %>
+ <% if @comment.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
+
+ <ul>
+ <% @comment.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :body %><br />
+ <%= f.text_area :body %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
22 app/views/parrot/comments/new.html.erb
@@ -1,21 +1 @@
-<%= form_for([@commentable_type, @comment]) do |f| %>
- <% if @comment.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
-
- <ul>
- <% @comment.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :body %><br />
- <%= f.text_area :body %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
+<%= render 'form', object: @commentable_type %>
View
2  lib/parrot.rb
@@ -8,7 +8,7 @@ def self.author_class
class Engine < Rails::Engine
engine_name 'parrot'
- isolate_namespace Parrot
+ # isolate_namespace Parrot # FIXME: tries application url helpers (undefined method `post_comments_path')
initializer 'parrot' do |app|
ActiveSupport.on_load(:active_record) do
View
4 test/dummy/app/models/user.rb
@@ -7,4 +7,8 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
+
+ def to_s
+ email.split('@').first
+ end
end
View
1  test/dummy/app/views/posts/show.html.erb
@@ -11,6 +11,7 @@
<hr>
<h2>Comments</h2>
<%= render @post.comments %>
+<%= render 'parrot/comments/form', :object => @post %>
<%= link_to 'Edit', edit_post_path(@post) %> |
<%= link_to 'Back', posts_path %>
View
BIN  test/dummy/db/development.sqlite3
Binary file not shown

0 comments on commit 151171a

Please sign in to comment.
Something went wrong with that request. Please try again.