Commit b1c97097313bcc1404339b655337519503519b29

Authored by Gabriela Navarro
1 parent fb61c078
Exists in temp_ratings

Add relation to rate and comment.

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb
1 class CommunitiesRatingsPluginProfileController < ProfileController 1 class CommunitiesRatingsPluginProfileController < ProfileController
2 2
  3 + before_filter :login_required
3 # Inside a community, receive a ajax from the current logged person with its 4 # Inside a community, receive a ajax from the current logged person with its
4 # rate for the community. If the user already rated this commnity, update its 5 # rate for the community. If the user already rated this commnity, update its
5 # rate value or else, create a new one 6 # rate value or else, create a new one
@@ -31,10 +32,10 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController @@ -31,10 +32,10 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
31 @plugins = plugins 32 @plugins = plugins
32 community_rating = get_community_rating(user, profile) 33 community_rating = get_community_rating(user, profile)
33 @actual_rate_value = if community_rating.value 34 @actual_rate_value = if community_rating.value
34 - community_rating.value  
35 - else  
36 - 0  
37 - end 35 + community_rating.value
  36 + else
  37 + 0
  38 + end
38 39
39 if request.post? 40 if request.post?
40 unless params[:comments][:body].empty? 41 unless params[:comments][:body].empty?
@@ -42,6 +43,8 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController @@ -42,6 +43,8 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
42 comment.author = current_user.person 43 comment.author = current_user.person
43 comment.community = profile 44 comment.community = profile
44 comment.save 45 comment.save
  46 + community_rating.comment = comment
  47 + community_rating.save
45 else 48 else
46 session[:notice] = _("You need to provide a decription to make a comment") 49 session[:notice] = _("You need to provide a decription to make a comment")
47 redirect_to action: :new_rating 50 redirect_to action: :new_rating
plugins/communities_ratings/db/migrate/20150707133834_add_community_rating_to_comments.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +class AddCommunityRatingToComments < ActiveRecord::Migration
  2 + def self.up
  3 + change_table :comments do |t|
  4 + t.belongs_to :community_rating
  5 + end
  6 + end
  7 +
  8 + def self.down
  9 + remove_column :comments, :community_rating_id
  10 + end
  11 +end
plugins/communities_ratings/lib/community_rating.rb
@@ -12,4 +12,5 @@ class CommunityRating &lt; ActiveRecord::Base @@ -12,4 +12,5 @@ class CommunityRating &lt; ActiveRecord::Base
12 validates :community_id, :person_id, 12 validates :community_id, :person_id,
13 :presence => true 13 :presence => true
14 14
  15 + has_one :comment
15 end 16 end
plugins/communities_ratings/lib/ext/comments.rb
@@ -3,4 +3,6 @@ require_dependency &quot;comment&quot; @@ -3,4 +3,6 @@ require_dependency &quot;comment&quot;
3 class Comment 3 class Comment
4 alias :community :source 4 alias :community :source
5 alias :community= :source= 5 alias :community= :source=
  6 +
  7 + belongs_to :community_rating
6 end 8 end