Commit 14b34706cdf9618601b3fad420c33d4f3822f0c8
Exists in
ratings_minor_fixes
and in
3 other branches
Merge branch 'fix_rating_creation_error_message' into 'master'
Adds models error message to session notice Adds models error messages instead of a fixed message for every error. See merge request !947
Showing
4 changed files
with
13 additions
and
14 deletions
Show diff stats
app/helpers/application_helper.rb
| @@ -1130,7 +1130,7 @@ module ApplicationHelper | @@ -1130,7 +1130,7 @@ module ApplicationHelper | ||
| 1130 | content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do | 1130 | content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do |
| 1131 | content_tag(:h2, _('Errors while saving')) + | 1131 | content_tag(:h2, _('Errors while saving')) + |
| 1132 | content_tag(:ul) do | 1132 | content_tag(:ul) do |
| 1133 | - safe_join(errors.map { |err| content_tag(:li, err) }) | 1133 | + safe_join(errors.map { |err| content_tag(:li, err.html_safe) }) |
| 1134 | end | 1134 | end |
| 1135 | end | 1135 | end |
| 1136 | end | 1136 | end |
plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
| @@ -37,20 +37,17 @@ class OrganizationRatingsPluginProfileController < ProfileController | @@ -37,20 +37,17 @@ class OrganizationRatingsPluginProfileController < ProfileController | ||
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | def create_new_rate | 39 | def create_new_rate |
| 40 | - rating = OrganizationRating.new(params[:organization_rating]) | ||
| 41 | - rating.person = current_user.person | ||
| 42 | - rating.organization = profile | ||
| 43 | - rating.value = params[:organization_rating_value] if params[:organization_rating_value] | 40 | + @rating = OrganizationRating.new(params[:organization_rating]) |
| 41 | + @rating.person = current_user.person | ||
| 42 | + @rating.organization = profile | ||
| 43 | + @rating.value = params[:organization_rating_value] if params[:organization_rating_value] | ||
| 44 | 44 | ||
| 45 | - if rating.save | ||
| 46 | - @plugins.dispatch(:organization_ratings_plugin_rating_created, rating, params) | ||
| 47 | - create_rating_comment(rating) | 45 | + if @rating.save |
| 46 | + @plugins.dispatch(:organization_ratings_plugin_rating_created, @rating, params) | ||
| 47 | + create_rating_comment(@rating) | ||
| 48 | session[:notice] = _("%s successfully rated!") % profile.name | 48 | session[:notice] = _("%s successfully rated!") % profile.name |
| 49 | - else | ||
| 50 | - session[:notice] = _("Sorry, there were problems rating this profile.") | 49 | + redirect_to profile.url |
| 51 | end | 50 | end |
| 52 | - | ||
| 53 | - redirect_to profile.url | ||
| 54 | end | 51 | end |
| 55 | 52 | ||
| 56 | def create_rating_comment(rating) | 53 | def create_rating_comment(rating) |
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
| @@ -46,7 +46,7 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas | @@ -46,7 +46,7 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas | ||
| 46 | test "do not create community_rating without a rate value" do | 46 | test "do not create community_rating without a rate value" do |
| 47 | post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil | 47 | post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil |
| 48 | 48 | ||
| 49 | - assert_equal "Sorry, there were problems rating this profile.", session[:notice] | 49 | + assert_tag :tag => 'div', :attributes => {:class => /errorExplanation/}, :content => /Value can't be blank/ |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | test "do not create two ratings on Community when vote once config is true" do | 52 | test "do not create two ratings on Community when vote once config is true" do |
plugins/organization_ratings/views/organization_ratings_plugin_profile/new_rating.html.erb
| 1 | +<%= error_messages_for 'rating' %> | ||
| 2 | + | ||
| 1 | <% config = env_organization_ratings_config %> | 3 | <% config = env_organization_ratings_config %> |
| 2 | <% if logged_in? %> | 4 | <% if logged_in? %> |
| 3 | <%= render :partial => "new_rating_fields" %> | 5 | <%= render :partial => "new_rating_fields" %> |
| @@ -15,4 +17,4 @@ | @@ -15,4 +17,4 @@ | ||
| 15 | 17 | ||
| 16 | <div id='pagination-profiles'> | 18 | <div id='pagination-profiles'> |
| 17 | <%= pagination_links @users_ratings, :param_name => 'npage' %> | 19 | <%= pagination_links @users_ratings, :param_name => 'npage' %> |
| 18 | -</div> | ||
| 19 | \ No newline at end of file | 20 | \ No newline at end of file |
| 21 | +</div> |