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 1 class CommunitiesRatingsPluginProfileController < ProfileController
2 2  
  3 + before_filter :login_required
3 4 # Inside a community, receive a ajax from the current logged person with its
4 5 # rate for the community. If the user already rated this commnity, update its
5 6 # rate value or else, create a new one
... ... @@ -31,10 +32,10 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
31 32 @plugins = plugins
32 33 community_rating = get_community_rating(user, profile)
33 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 40 if request.post?
40 41 unless params[:comments][:body].empty?
... ... @@ -42,6 +43,8 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
42 43 comment.author = current_user.person
43 44 comment.community = profile
44 45 comment.save
  46 + community_rating.comment = comment
  47 + community_rating.save
45 48 else
46 49 session[:notice] = _("You need to provide a decription to make a comment")
47 50 redirect_to action: :new_rating
... ...
plugins/communities_ratings/db/migrate/20150707133834_add_community_rating_to_comments.rb 0 → 100644
... ... @@ -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 12 validates :community_id, :person_id,
13 13 :presence => true
14 14  
  15 + has_one :comment
15 16 end
... ...
plugins/communities_ratings/lib/ext/comments.rb
... ... @@ -3,4 +3,6 @@ require_dependency &quot;comment&quot;
3 3 class Comment
4 4 alias :community :source
5 5 alias :community= :source=
  6 +
  7 + belongs_to :community_rating
6 8 end
... ...