Class: HomeController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- HomeController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/home_controller.rb
Overview
This controller manage the views refering to user
Instance Method Summary collapse
-
#favorite ⇒ Object
GET /home/favorite.
-
#favorite_create ⇒ Object
POST /faq/1 or /faq/1.json.
-
#favorite_destroy ⇒ Object
DELETE /faq/1 or /faq/1.json.
-
#favorite_list ⇒ Object
GET /home/favorite_list.
-
#index ⇒ Object
GET /home/index.
-
#list ⇒ Object
GET /home/list.
-
#propose ⇒ Object
GET /home/propose.
-
#propose_send ⇒ Object
POST /home/propose.
-
#search ⇒ Object
GET /:text.
-
#search_by_title ⇒ Object
GET /faq/:find_by_title.
-
#show ⇒ Object
GET /home/1/show.
Instance Method Details
#favorite ⇒ Object
GET /home/favorite
render favorite
83 |
# File 'app/controllers/home_controller.rb', line 83 def favorite; end |
#favorite_create ⇒ Object
POST /faq/1 or /faq/1.json
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/home_controller.rb', line 98 def favorite_create if UserFaq.create(user_id: current_user.id, faq_id: @faq.id) flash.now[:success] = 'Faq aggiunta tra i preferiti!' get_user_faqs else flash.now[:success] = 'Si è verificato un errore durante la creazione della Faq nei preferiti!' end render turbo_stream: [ turbo_stream.replace(:flashes, partial: "flashes"), turbo_stream.replace("faq_#{@faq.id}", partial: "home/faq", locals: {faq: @faq, user_faq_ids: @user_faq_ids}) ] end |
#favorite_destroy ⇒ Object
DELETE /faq/1 or /faq/1.json
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/home_controller.rb', line 112 def favorite_destroy user_faq = UserFaq.find_by(user_id: current_user.id, faq_id: @faq.id) return if user_faq.blank? if user_faq.destroy flash.now[:success] = 'Faq rimossa dai preferiti!' get_user_faqs else flash.now[:error] = 'Si è verificato un errore durante la cancellazione della Faq dai preferiti!' end render turbo_stream: [ turbo_stream.replace(:flashes, partial: "flashes"), turbo_stream.replace("faq_#{@faq.id}", partial: "home/faq", locals: {faq: @faq, user_faq_ids: @user_faq_ids}) ] end |
#favorite_list ⇒ Object
GET /home/favorite_list
render favorite_list
89 90 91 92 93 94 95 |
# File 'app/controllers/home_controller.rb', line 89 def favorite_list @filters = filter_params @page = params[:page] || 1 @faqs = @user.faqs.accessible_by(current_ability).actived.approved @faqs = @faqs.where("title ilike '%?%'", @filters[:text]) if @filters[:text].present? @pagy, @faqs = pagy(@faqs, page: @page, link_extra: "data-turbo-frame='faqs'") end |
#index ⇒ Object
GET /home/index
render faqs
16 17 18 19 20 21 |
# File 'app/controllers/home_controller.rb', line 16 def index @categories = ActsAsTaggableOn::Tag.most_used(Settings.faq.categories_on_top) faqs = Faq.accessible_by(current_ability).actived.approved @faqs = faqs.tagged_with(@categories, any: true) @sample = faqs.find(faqs.pluck(:id).sample) end |
#list ⇒ Object
GET /home/list
render user faqs
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/home_controller.rb', line 27 def list @filters = filter_params @page = params[:page] || 1 faqs = Faq.accessible_by(current_ability).actived.approved @evidences = faqs.evidenced.limit(Settings.faq.max_faqs_in_evidence) @tops = faqs.approved.where('counter > 0').on_top(Settings.faq.most_requested) if @filters[:text].present? || @filters[:category].present? faqs = faqs.search_by_title(@filters[:text].gsub(/[^\w\s]+/, ' ').remove(/[^\w\s]+/)) if @filters[:text].present? faqs = faqs.tagged_with(@filters[:category].remove(/[^\w\s]+/), any: true) if @filters[:category].present? @faqs = faqs end flash.now[:success] = 'Caricamento completato' end |
#propose ⇒ Object
GET /home/propose
render propose
77 |
# File 'app/controllers/home_controller.rb', line 77 def propose; end |
#propose_send ⇒ Object
POST /home/propose
render propose_send
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/home_controller.rb', line 132 def propose_send @author = propose_params[:author_id].present? ? User.find(propose_params[:author_id]) : '' if @author.present? && propose_params[:title].present? UserMailer.with(author: @author, propose: propose_params).propose_email.deliver_now User.admins.map { |u| FaqMailer.with(user: u, author: @author, propose: propose_params).propose_email.deliver_now } flash.now[:success] = 'Invio proposta completato' else flash.now[:error] = 'Non è stato possibile inviare la richiesta' if @author.blank? flash.now[:error] = 'Il titolo è obbligatorio!' if propose_params[:title].blank? end render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end |
#search ⇒ Object
GET /:text
render index
53 54 55 56 57 58 |
# File 'app/controllers/home_controller.rb', line 53 def search @filters = filter_params @filters[:text] = params[:text].gsub(/[^\w\s]+/, ' ').remove(/[^\w\s]+/) if params[:text].present? flash.now[:success] = 'Caricamento completato' render :index end |
#search_by_title ⇒ Object
GET /faq/:find_by_title
render show
64 65 66 67 68 69 70 71 |
# File 'app/controllers/home_controller.rb', line 64 def search_by_title @filters = filter_params @filters[:text] = params[:text].gsub(/[^\w\s]+/, ' ').remove(/[^\w\s]+/) if params[:text].present? faqs = Faq.accessible_by(current_ability) @faq = faqs.find_by("LOWER(title) = ?", @filters[:text].gsub(/[^\w\s]+/, ' ').remove(/[^\w\s]+/).downcase) if @filters[:text].present? FaqCounterJob.perform_later(faq: @faq) render :show end |
#show ⇒ Object
GET /home/1/show
render faq
45 46 47 |
# File 'app/controllers/home_controller.rb', line 45 def show FaqCounterJob.perform_later(faq: @faq) end |