diff --git a/app/controllers/badges_controller.rb b/app/controllers/badges_controller.rb index 07148f0b652d908dbbf4b94c1ab0e301ac82bf4a..5d7b3d28e81ae339e10a20ec594c642329234f1b 100644 --- a/app/controllers/badges_controller.rb +++ b/app/controllers/badges_controller.rb @@ -21,6 +21,7 @@ class BadgesController < ApplicationController respond_to do |format| if @badge.save + Rails.cache.delete 'network/badges/badge_ids' format.html { redirect_to badges_url, notice: 'Badge was successfully created.' } format.json { render :show, status: :created, location: @badge } else @@ -34,6 +35,7 @@ class BadgesController < ApplicationController def update respond_to do |format| if @badge.update(badge_params) + Rails.cache.delete 'network/badges/badge_ids' format.html { redirect_to badges_url, notice: 'Badge was successfully updated.' } format.json { render :show, status: :ok, location: @badge } else @@ -46,6 +48,7 @@ class BadgesController < ApplicationController # DELETE /badges/1 or /badges/1.json def destroy @badge.destroy + Rails.cache.delete 'network/badges/badge_ids' respond_to do |format| format.html { redirect_to badges_url, notice: 'Badge was successfully destroyed.' } @@ -80,6 +83,9 @@ class BadgesController < ApplicationController when 'User' @user_badge.reference_url = Rails.application.routes.path_for(controller: 'users', action: 'show', id: @user_badge.badge_source_id) + when 'Tag' + @user_badge.reference_url = Rails.application.routes.path_for(controllers: 'tags', action: 'show', + id: @user_badge.badge_source_id) else @user_badge.reference_url = '' end @@ -105,7 +111,7 @@ class BadgesController < ApplicationController # Defines the available types of association for the UserBadge polymorphic relationship def badge_source_types - %w[Post User] + %w[Post User Tag] end # Only allow a list of trusted parameters through. diff --git a/app/views/badges/award.html.erb b/app/views/badges/award.html.erb index da539679471534501b89c820c22d7b9a674165e8..af291cd3a41ab9b9394986fa78c8729da26f1c99 100644 --- a/app/views/badges/award.html.erb +++ b/app/views/badges/award.html.erb @@ -15,7 +15,7 @@ Select which badge should be awarded. In case you want to create a new badge, you can do so <%= link_to "here", new_badge_path, class: 'link is-underlined', target: "_blank", 'aria-label': 'Add new badge' %> </span> - <%= f.select :badge, options_for_select(Badge.where(:manually_awardable => true).mapping.to_a, selected: []), + <%= f.select :badge, options_for_select(Badge.where(manually_awardable: true).pluck(:title, :id), selected: []), { include_blank: false }, multiple: false, class: 'form-element' %> </div> @@ -32,7 +32,7 @@ <div class="grid--cell is-6 is-12-sm"> <div class="form-caption">Entity Type</div> <%= f.select :badge_source_type, options_for_select(@entity_types, selected: []), - { include_blank: false }, class: 'form-element' %> + { include_blank: true }, class: 'form-element' %> </div> <div class="grid--cell is-6 is-12-sm"> <div class="form-caption">Id of the entity</div>