Commit b1c97097313bcc1404339b655337519503519b29
1 parent
fb61c078
Exists in
communities_ratings
Add relation to rate and comment.
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
4 changed files
with
21 additions
and
4 deletions
Show diff stats
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 < ProfileController | @@ -31,10 +32,10 @@ class CommunitiesRatingsPluginProfileController < 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 < ProfileController | @@ -42,6 +43,8 @@ class CommunitiesRatingsPluginProfileController < 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
plugins/communities_ratings/lib/community_rating.rb
plugins/communities_ratings/lib/ext/comments.rb
| @@ -3,4 +3,6 @@ require_dependency "comment" | @@ -3,4 +3,6 @@ require_dependency "comment" | ||
| 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 |