Created
January 19, 2011 23:34
-
-
Save kevinpfromnm/787113 to your computer and use it in GitHub Desktop.
Comments extract
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
class Comment < ActiveRecord::Base | |
hobo_model # Don't put anything above this | |
fields do | |
body :text, :required | |
timestamps | |
end | |
belongs_to :commentable, :polymorphic => true, :counter_cache => true | |
belongs_to :owner, :class_name => "User", :creator => true | |
named_scope :recent, lambda { |n| { :order => 'updated_at DESC', :limit => n } } | |
set_default_order "created_at DESC" | |
# --- Permissions --- # | |
def create_permitted? | |
owner_is? acting_user | |
end | |
def update_permitted? | |
acting_user.administrator? | |
end | |
def destroy_permitted? | |
acting_user.administrator? | |
end | |
def view_permitted?(field) | |
true | |
end | |
# other methods | |
def shortened_body | |
return body.slice(0,100) + "..." if body.length > 100 | |
body | |
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
<def tag="card" for="Comment" attrs="gravatar"> | |
<div class="card linkable comment" param="default"> | |
<gravatar:owner unless="&gravatar == 'false'" rating="pg" size="50" param /> | |
<h5 param="card-heading"><You:owner /> wrote <view:created_at format="on %B %d, %Y at %I:%M%p" param="card-timestamp" />:</h5> | |
<p><view:body param="card-body" /></p> | |
<delete-button class="actions" param /> | |
</div> | |
</def> | |
<def tag="comment-collection"> | |
<% cache :controller => :comments, :action => :commentcollection, :commentable_type => this.class, :commentable_id => this.id do %> | |
<div part="comment-collection"> | |
<collection:comments /> | |
</div> | |
<% end %> | |
<add-comment if="¤t_user.signed_up?" /> | |
</def> | |
<def tag="add-comment"> | |
<do with="&this.comments.new :owner => current_user"> | |
<form update="comment-collection" reset-form> | |
<h6>Add a comment</h6> | |
<input:body class="comment-body-input" /> | |
<after-submit uri="&object_url(this.commentable)" /> | |
<submit label="Add Comment"/> | |
</form> | |
</do> | |
</def> |
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
<extend tag="show-page"> | |
<old-show-page merge> | |
<append-content-body:> | |
<section class="collection-section" if="&this.respond_to?(:comments)"> | |
<h3 class="collection-heading">Comments</h3> | |
<comment-collection /> | |
</section> | |
</append-content-body:> | |
</old-show-page> | |
</extend> |
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
has_many :comments, :as => :commentable, :dependent => :destroy, :accessible => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment