Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:ftorghele/FoodCorp

  • Loading branch information...
commit aea4664f4604ad844d4e56adc5e4c14dda558632 2 parents 7ee7fe8 + 0f064c2
Franz Torghele authored May 26, 2011
2  Gemfile
@@ -5,7 +5,7 @@ gem 'mysql2'
5 5
 gem 'jquery-rails'
6 6
 gem "geocoder"
7 7
 
8  
-
  8
+gem 'acts_as_commentable_with_threading'
9 9
 gem 'devise'
10 10
 gem 'oa-oauth', :require => 'omniauth/oauth'
11 11
 
7  Gemfile.lock
@@ -29,6 +29,10 @@ GEM
29 29
       activesupport (= 3.0.5)
30 30
     activesupport (3.0.5)
31 31
     acts-as-messageable (0.1.0)
  32
+    acts_as_commentable_with_threading (1.1.1)
  33
+      activerecord (~> 3.0)
  34
+      activesupport (~> 3.0)
  35
+      moretea-awesome_nested_set
32 36
     addressable (2.2.4)
33 37
     arel (2.0.9)
34 38
     bcrypt-ruby (2.1.4)
@@ -81,6 +85,8 @@ GEM
81 85
       treetop (~> 1.4.8)
82 86
     mime-types (1.16)
83 87
     mocha (0.9.12)
  88
+    moretea-awesome_nested_set (1.4.3.1)
  89
+      activerecord (~> 3.0.0)
84 90
     multi_json (0.0.5)
85 91
     multipart-post (1.1.0)
86 92
     mysql2 (0.2.6)
@@ -145,6 +151,7 @@ PLATFORMS
145 151
 
146 152
 DEPENDENCIES
147 153
   acts-as-messageable
  154
+  acts_as_commentable_with_threading
148 155
   capybara
149 156
   devise
150 157
   faker
44  app/controllers/comments_controller.rb
... ...
@@ -1,44 +0,0 @@
1  
-class CommentsController < ApplicationController
2  
-
3  
-  before_filter :get_meal_comment, :only => [:edit, :update]
4  
-  before_filter :check_user, :only => [:edit]
5  
-
6  
-=begin
7  
-	#Meal Arrangement controller on acceptance
8  
-	def create
9  
-		comment = Comment.new(:user_id => current_user.id, :meal_id => params[:meal_id], :body => params[:body])
10  
-
11  
-		if comment.save
12  
-			redirect_to meal_path(params[:meal_id]), :notice => I18n.t('meal_comment.create_success')
13  
-		else
14  
-			redirect_to meal_path(params[:meal_id]), :notice => I18n.t('meal_comment.create_fail')
15  
-	end
16  
-=end
17  
-
18  
-	def destroy
19  
-
20  
-	end
21  
-
22  
-	def edit
23  
-	end
24  
-
25  
-	def update
26  
-		if @comment.update_attributes(params[:comment])
27  
-			redirect_to meal_path(@comment.meal_id), :notice => I18n.t('meal_comment.create_success')
28  
-		else
29  
-      		redirect_to edit_meal_path(@comment.meal_id),  :alert => I18n.t('meal_comment.create_fail')
30  
-    	end
31  
-	end
32  
-
33  
-  private
34  
-  def get_meal_comment
35  
-    @comment = Comment.find(params[:id])
36  
-  end
37  
-
38  
-  def check_user
39  
-    unless current_user.id == @comment.user_id
40  
-      redirect_to root_path, :notice => I18n.t('application.rights_fail')
41  
-    end
42  
-  end
43  
-
44  
-end
2  app/controllers/fellowships_controller.rb
@@ -11,7 +11,7 @@ def create
11 11
   end
12 12
 
13 13
   def destroy
14  
-    @fellowship = current_user.fellowships.find(params[:id])
  14
+    @fellowship = current_user.fellowships.get_fellowship params[:id]
15 15
     if @fellowship.destroy
16 16
       flash[:notice] = I18n.t('fellowships.destroy_success') 
17 17
       redirect_to :back
4  app/controllers/meal_arrangements_controller.rb
@@ -30,11 +30,9 @@ def update
30 30
         meal = Meal.find(current_meal_id)
31 31
         meal.slots -= 1
32 32
         meal.save
33  
-        comment = Comment.new(:user_id => @meal_arrangement.user_id, :meal_id => current_meal_id, :body => I18n.t('meal_comment.default_body') )
34  
-        comment.save
35 33
         current_user.update_attribute(:points, current_user.points)
36 34
         puts(current_user.points)
37  
-        current_user.send_message(@meal_arrangement.user, I18n.t('message.accept'), '<a href="'+edit_comment_path(comment.id)+'">Give a Comment</a>' )
  35
+        current_user.send_message(@meal_arrangement.user, I18n.t('message.accept'), I18n.t('message.info') )
38 36
         redirect_to :back, :notice => I18n.t('meal_arrangements.accept_success')
39 37
     else
40 38
         redirect_to :back, :notice => I18n.t('meal_arrangements.accept_fail')
54  app/models/comment.rb
... ...
@@ -1,14 +1,48 @@
1 1
 class Comment < ActiveRecord::Base
  2
+  acts_as_nested_set :scope => [:commentable_id, :commentable_type]
  3
+  
  4
+  validates_presence_of :body
  5
+  validates_presence_of :user
  6
+  
  7
+  # NOTE: install the acts_as_votable plugin if you 
  8
+  # want user to vote on the quality of comments.
  9
+  #acts_as_voteable
  10
+  
  11
+  # NOTE: Comments belong to a user
  12
+  belongs_to :user
  13
+  
  14
+  # Helper class method that allows you to build a comment
  15
+  # by passing a commentable object, a user_id, and comment text
  16
+  # example in readme
  17
+  def self.build_from(obj, user_id, comment)
  18
+    c = self.new
  19
+    c.commentable_id = obj.id 
  20
+    c.commentable_type = obj.class.name 
  21
+    c.body = comment 
  22
+    c.user_id = user_id
  23
+    c
  24
+  end
  25
+  
  26
+  #helper method to check if a comment has children
  27
+  def has_children?
  28
+    self.children.size > 0 
  29
+  end
  30
+  
  31
+  # Helper class method to lookup all comments assigned
  32
+  # to all commentable types for a given user.
  33
+  scope :find_comments_by_user, lambda { |user|
  34
+    where(:user_id => user.id).order('created_at DESC')
  35
+  }
2 36
 
3  
-	belongs_to :meal
4  
-	belongs_to :user
5  
-	has_many :reports, :dependent => :destroy
6  
-
7  
-	attr_accessible :user_id, :meal_id, :body, :visible
8  
-
9  
-	validates :user_id, :presence => true
10  
-	validates :meal_id, :presence => true
11  
-	validates :body, :presence => true
12  
-
  37
+  # Helper class method to look up all comments for 
  38
+  # commentable class name and commentable id.
  39
+  scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
  40
+    where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC')
  41
+  }
13 42
 
  43
+  # Helper class method to look up a commentable object
  44
+  # given the commentable class name and id 
  45
+  def self.find_commentable(commentable_str, commentable_id)
  46
+    commentable_str.constantize.find(commentable_id)
  47
+  end
14 48
 end
4  app/models/fellowship.rb
@@ -8,4 +8,8 @@ class Fellowship < ActiveRecord::Base
8 8
   validates :user_id, :presence => true
9 9
   validates :follower_id, :presence => true
10 10
   validates_uniqueness_of :user_id, :scope => :follower_id
  11
+
  12
+  def self.get_fellowship arg
  13
+    where(:id => arg)
  14
+  end
11 15
 end
2  app/models/meal.rb
@@ -18,4 +18,6 @@ class Meal < ActiveRecord::Base
18 18
   geocoded_by :address, :latitude  => :lat, :longitude => :lon
19 19
   reverse_geocoded_by :lat, :lon
20 20
   
  21
+#  acts_as_commentable
  22
+
21 23
 end
2  app/models/meal_arrangement.rb
@@ -12,4 +12,6 @@ class MealArrangement < ActiveRecord::Base
12 12
   belongs_to :user
13 13
   belongs_to :meal
14 14
   
  15
+
  16
+
15 17
 end
7  app/views/users/_meal.html.erb
@@ -15,12 +15,7 @@
15 15
     <% end %>
16 16
   <% end %>
17 17
 
18  
-  <% meal.comments.each do |comment| %>
19  
-  	<% if comment.visible == true %>
20  
-  		<%= link_to comment.user.first_name+" "+comment.user.last_name, user_path(comment.user_id) %><br>
21  
-  		<div class="comments"><%= comment.body %></div>
22  
-  	<% end %>
23  
-  <% end %>
  18
+
24 19
 
25 20
 </div>
26 21
 
4  db/migrate/20110413133754_create_meals.rb
@@ -16,9 +16,11 @@ def self.up
16 16
 
17 17
       t.timestamps
18 18
     end
  19
+
  20
+      add_index :meals, :user_id
19 21
   end
20 22
 
21  
-  add_index :meals, :user_id,           :unique => true
  23
+
22 24
 
23 25
   def self.down
24 26
     drop_table :meals
3  db/migrate/20110419142401_create_fellowships.rb
@@ -6,9 +6,10 @@ def self.up
6 6
 
7 7
       t.timestamps
8 8
     end
  9
+      add_index :fellowships, :user_id
9 10
   end
10 11
 
11  
-  add_index :fellowships, :user_id,                :unique => true
  12
+
12 13
 
13 14
   def self.down
14 15
     drop_table :fellowships
6  db/migrate/20110419152953_create_meal_arrangements.rb
@@ -7,10 +7,12 @@ def self.up
7 7
 
8 8
       t.timestamps
9 9
     end
  10
+
  11
+  add_index :meal_arrangements, :meal_id
  12
+  add_index :meal_arrangements, :user_id
  13
+
10 14
   end
11 15
 
12  
-  add_index :meal_arrangements, :meal_id,                :unique => true
13  
-  add_index :meal_arrangements, :user_id,                :unique => true
14 16
 
15 17
   def self.down
16 18
     drop_table :meal_arrangements
20  db/migrate/20110515151843_create_comments.rb
... ...
@@ -1,20 +0,0 @@
1  
-class CreateComments < ActiveRecord::Migration
2  
-  def self.up
3  
-    create_table :comments do |t|
4  
-      t.text :body
5  
-      t.integer :user_id
6  
-      t.integer :meal_id
7  
-      t.integer :report_count, :default => 0
8  
-      t.boolean :visible, :default => false
9  
-      
10  
-      t.timestamps
11  
-    end
12  
-  end
13  
-
14  
-  add_index :comments, :user_id,                :unique => true
15  
-  add_index :comments, :meal_id,                :unique => true
16  
-
17  
-  def self.down
18  
-    drop_table :comments
19  
-  end
20  
-end
21  db/migrate/20110525172819_acts_as_commentable_with_threading_migration.rb
... ...
@@ -0,0 +1,21 @@
  1
+class ActsAsCommentableWithThreadingMigration < ActiveRecord::Migration
  2
+  def self.up
  3
+    create_table :comments, :force => true do |t|
  4
+      t.integer :commentable_id, :default => 0
  5
+      t.string :commentable_type, :default => ""
  6
+      t.string :title, :default => ""
  7
+      t.text :body, :default => ""
  8
+      t.string :subject, :default => ""
  9
+      t.integer :user_id, :default => 0, :null => false
  10
+      t.integer :parent_id, :lft, :rgt
  11
+      t.timestamps
  12
+    end
  13
+    
  14
+    add_index :comments, :user_id
  15
+    add_index :comments, :commentable_id
  16
+  end
  17
+  
  18
+  def self.down
  19
+    drop_table :comments
  20
+  end
  21
+end
26  db/schema.rb
@@ -10,18 +10,25 @@
10 10
 #
11 11
 # It's strongly recommended to check this file into your version control system.
12 12
 
13  
-ActiveRecord::Schema.define(:version => 20110515151843) do
  13
+ActiveRecord::Schema.define(:version => 20110525172819) do
14 14
 
15 15
   create_table "comments", :force => true do |t|
  16
+    t.integer  "commentable_id",   :default => 0
  17
+    t.string   "commentable_type", :default => ""
  18
+    t.string   "title",            :default => ""
16 19
     t.text     "body"
17  
-    t.integer  "user_id"
18  
-    t.integer  "meal_id"
19  
-    t.integer  "report_count", :default => 0
20  
-    t.boolean  "visible",      :default => false
  20
+    t.string   "subject",          :default => ""
  21
+    t.integer  "user_id",          :default => 0,  :null => false
  22
+    t.integer  "parent_id"
  23
+    t.integer  "lft"
  24
+    t.integer  "rgt"
21 25
     t.datetime "created_at"
22 26
     t.datetime "updated_at"
23 27
   end
24 28
 
  29
+  add_index "comments", ["commentable_id"], :name => "index_comments_on_commentable_id"
  30
+  add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
  31
+
25 32
   create_table "fellowships", :force => true do |t|
26 33
     t.integer  "user_id"
27 34
     t.integer  "follower_id"
@@ -29,6 +36,8 @@
29 36
     t.datetime "updated_at"
30 37
   end
31 38
 
  39
+  add_index "fellowships", ["user_id"], :name => "index_fellowships_on_user_id"
  40
+
32 41
   create_table "meal_arrangements", :force => true do |t|
33 42
     t.integer  "meal_id"
34 43
     t.integer  "user_id"
@@ -37,6 +46,9 @@
37 46
     t.boolean  "acceptance"
38 47
   end
39 48
 
  49
+  add_index "meal_arrangements", ["meal_id"], :name => "index_meal_arrangements_on_meal_id"
  50
+  add_index "meal_arrangements", ["user_id"], :name => "index_meal_arrangements_on_user_id"
  51
+
40 52
   create_table "meals", :force => true do |t|
41 53
     t.string   "title"
42 54
     t.text     "description"
@@ -55,6 +67,8 @@
55 67
     t.integer  "slots"
56 68
   end
57 69
 
  70
+  add_index "meals", ["user_id"], :name => "index_meals_on_user_id"
  71
+
58 72
   create_table "messages", :force => true do |t|
59 73
     t.string  "topic"
60 74
     t.text    "body"
@@ -101,7 +115,7 @@
101 115
     t.integer  "avatar_file_size"
102 116
     t.datetime "avatar_updated_at"
103 117
     t.boolean  "use_fb_avatar"
104  
-    t.integer  "points",                              :default => 0
  118
+    t.integer  "points",                              :default => 1
105 119
     t.text     "info_field"
106 120
   end
107 121
 

0 notes on commit aea4664

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