module Enjoy::Feedback::Controllers::Contacts
Public Instance Methods
create()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 24 def create @contact_message = model.new(message_params) after_initialize if Enjoy::Feedback.config.captcha if Enjoy::Feedback.config.recaptcha_support if verify_recaptcha meth = :save else meth = :valid? @recaptcha_error = I18n.t('enjoy.errors.feedback.recaptcha') end elsif Enjoy::Feedback.config.simple_captcha_support meth = :save_with_captcha else meth = :save end else meth = :save end if @contact_message.send(meth) after_create if request.xhr? && process_ajax ajax_success else redirect_after_done end else render_contacts_error end end
index()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 12 def index @contact_message = model.new after_initialize xhr_checker end
new()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 18 def new @contact_message = model.new after_initialize xhr_checker end
sent()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 59 def sent end
Private Instance Methods
after_create()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 89 def after_create # overrideable hook for updating message end
after_initialize()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 87 def after_initialize end
ajax_success()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 75 def ajax_success render partial: success_partial # render json: {ok: true} end
form_partial()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 92 def form_partial "enjoy/feedback/contacts/form" end
message_params()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 101 def message_params params.require(model.to_param.gsub("::", "").underscore).permit( Enjoy::Feedback.config.fields.keys + [:name, :email, :phone, :content, :captcha, :captcha_key] ) end
model()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 98 def model Enjoy::Feedback::ContactMessage end
process_ajax()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 72 def process_ajax true end
redirect_after_done()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 79 def redirect_after_done redirect_to action: :sent end
render_contacts_error()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 63 def render_contacts_error if request.xhr? && process_ajax render partial: form_partial, status: 422 # render json: {errors: @contact_message.errors}, status: 422 else flash.now[:alert] = @contact_message.errors.full_messages.join("\n") render action: Enjoy::Feedback.configuration.recreate_contact_message_action, status: 422 end end
success_partial()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 95 def success_partial "enjoy/feedback/contacts/success" end
xhr_checker()
click to toggle source
# File lib/enjoy/feedback/controllers/contacts.rb, line 82 def xhr_checker if request.xhr? render layout: false end end