The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class Settings::FeaturedTagsController < Settings::BaseController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :set_featured_tags, only: :index
  6. before_action :set_featured_tag, except: [:index, :create]
  7. before_action :set_most_used_tags, only: :index
  8. def index
  9. @featured_tag = FeaturedTag.new
  10. end
  11. def create
  12. @featured_tag = current_account.featured_tags.new(featured_tag_params)
  13. @featured_tag.reset_data
  14. if @featured_tag.save
  15. redirect_to settings_featured_tags_path
  16. else
  17. set_featured_tags
  18. set_most_used_tags
  19. render :index
  20. end
  21. end
  22. def destroy
  23. @featured_tag.destroy!
  24. redirect_to settings_featured_tags_path
  25. end
  26. private
  27. def set_featured_tag
  28. @featured_tag = current_account.featured_tags.find(params[:id])
  29. end
  30. def set_featured_tags
  31. @featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?)
  32. end
  33. def set_most_used_tags
  34. @most_used_tags = Tag.most_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
  35. end
  36. def featured_tag_params
  37. params.require(:featured_tag).permit(:name)
  38. end
  39. end