Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added taxons decorator and moved comment to spree directory
- Loading branch information
1 parent
64dcad1
commit 76aef10
Showing
4 changed files
with
60 additions
and
0 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,52 @@ | ||
module Spree | ||
class Comment < ActiveRecord::Base | ||
acts_as_nested_set :scope => [:commentable_id, :commentable_type] | ||
|
||
validates_presence_of :body | ||
validates_presence_of :user | ||
|
||
# NOTE: install the acts_as_votable plugin if you | ||
# want user to vote on the quality of comments. | ||
#acts_as_voteable | ||
|
||
belongs_to :commentable, :polymorphic => true | ||
|
||
# NOTE: Comments belong to a user | ||
belongs_to :user | ||
|
||
# Helper class method that allows you to build a comment | ||
# by passing a commentable object, a user_id, and comment text | ||
# example in readme | ||
def self.build_from(obj, user_id, comment) | ||
c = self.new | ||
c.commentable_id = obj.id | ||
c.commentable_type = obj.class.base_class.name | ||
c.body = comment | ||
c.user_id = user_id | ||
c | ||
end | ||
|
||
#helper method to check if a comment has children | ||
def has_children? | ||
self.children.size > 0 | ||
end | ||
|
||
# Helper class method to lookup all comments assigned | ||
# to all commentable types for a given user. | ||
scope :find_comments_by_user, lambda { |user| | ||
where(:user_id => user.id).order('created_at DESC') | ||
} | ||
|
||
# Helper class method to look up all comments for | ||
# commentable class name and commentable id. | ||
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id| | ||
where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC') | ||
} | ||
|
||
# Helper class method to look up a commentable object | ||
# given the commentable class name and id | ||
def self.find_commentable(commentable_str, commentable_id) | ||
commentable_str.constantize.find(commentable_id) | ||
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,8 @@ | ||
Spree::Taxon.class_eval do | ||
has_and_belongs_to_many :pages, :join_table => 'spree_pages_taxons' | ||
|
||
def active_products | ||
scope = pages.published | ||
scope | ||
end | ||
end |
Empty file.
Empty file.