module Hancock::Faq::Controllers::Questions
Public Instance Methods
after_create()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 146 def after_create # overrideable hook for updating message end
after_initialize()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 144 def after_initialize end
ajax_success()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 131 def ajax_success render partial: success_partial # render json: {ok: true} end
cache_fields?()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 87 def cache_fields? ['new', 'index'].include? action_name end
cache_key()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 90 def cache_key 'hancock_faq_question_fields'.freeze end
category_class()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 159 def category_class Hancock::Faq::Category end
create()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 43 def create @question = question_class.new(question_params) if Hancock::Faq.config.captcha if Hancock::Faq.config.recaptcha_support if verify_recaptcha meth = :save else meth = :valid? @recaptcha_error = I18n.t('hancock.errors.faq.recaptcha') end elsif Hancock::Faq.config.simple_captcha_support meth = :save_with_captcha else meth = :save end else meth = :save end if @question.send(meth) after_create if request.xhr? && process_ajax ajax_success else redirect_after_done end else render_faq_error end end
fields_partial()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 93 def fields_partial "hancock/faq/questions/#{(Hancock::Faq.config.model_settings_support ? 'fields' : 'fields_with_settings')}".freeze end
form_partial()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 149 def form_partial "hancock/faq/questions/form" end
hancock_faq_question_update_captcha_path()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 81 def hancock_faq_question_update_captcha_path url_for(action: :update_captcha, time: Time.new.to_i, only_path: true) end
index()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 10 def index if Hancock::Faq.config.breadcrumbs_on_rails_support add_breadcrumb I18n.t('hancock.breadcrumbs.faq'), :hancock_faq_path end @questions = question_class.enabled.sorted.page(params[:page]).per(per_page) # index_crumbs after_initialize render locals: locals unless xhr_checker end
is_cache_fields()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 84 def is_cache_fields cache_fields? end
locals()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 108 def locals { is_cache_fields: is_cache_fields, cache_key: cache_key, fields_partial: fields_partial, settings_scope: settings_scope, recaptcha_options: recaptcha_options } end
page_title()
click to toggle source
Calls superclass method
# File lib/hancock/faq/controllers/questions.rb, line 35 def page_title if @question @question.page_title else super end end
per_page()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 166 def per_page 10 end
process_ajax()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 128 def process_ajax true end
question_class()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 162 def question_class Hancock::Faq::Question end
question_params()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 155 def question_params params[:hancock_faq_question].permit(:question_text, :author_name, :author_email, :captcha, :captcha_key) end
recaptcha_options()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 105 def recaptcha_options {} end
redirect_after_done()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 135 def redirect_after_done redirect_to action: :sent end
render_faq_error()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 119 def render_faq_error if request.xhr? && process_ajax render partial: form_partial, status: 422 # render json: {errors: @contact_message.errors}, status: 422 else flash.now[:alert] = @question.errors.full_messages.join("\n") render action: Hancock::Faq.configuration.recreate_contact_message_action, status: 422 end end
settings_scope()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 96 def settings_scope if Hancock::Faq.config.model_settings_support question_class.settings elsif defined?(Settings) Settings.ns('FAQ') else nil end end
show()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 21 def show if Hancock::Faq.config.breadcrumbs_on_rails_support add_breadcrumb I18n.t('hancock.breadcrumbs.faq'), :hancock_faq_path end @question = question_class.enabled.find(params[:id]) if !@question.text_slug.blank? and @question.text_slug != params[:id] redirect_to hancock_faq_question_path(@question), status_code: 301 return end @parent_seo_page = find_seo_page(hancock_faq_categories_path) if @seo_page.blank? # item_crumbs end
success_partial()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 152 def success_partial "hancock/faq/questions/success" end
update_captcha()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 77 def update_captcha render layout: false end
xhr_checker()
click to toggle source
# File lib/hancock/faq/controllers/questions.rb, line 138 def xhr_checker if request.xhr? render layout: false, locals: locals return true end end