Sha256: c9a54b1ebc1e136a12dc07015597ec97be5af497a663d34bddbc31ce1345afbe

Contents?: true

Size: 1.57 KB

Versions: 109

Compression:

Stored size: 1.57 KB

Contents

module RocketCMS
  module Controllers
    module Contacts
      extend ActiveSupport::Concern
      def new
        @contact_message = model.new
        after_initialize
      end

      def create
        @contact_message = model.new(message_params)
        after_initialize
        if RocketCMS.config.contacts_captcha
          meth = :save_with_captcha
        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

      def sent
      end

      private
      def render_contacts_error
        if request.xhr? && process_ajax
          render json: {errors: @contact_message.errors}, status: 422
        else
          flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
          render action: "new", status: 422
        end
      end
      def process_ajax
        true
      end
      def ajax_success
        render json: {ok: true}
      end
      def redirect_after_done
        redirect_to :contacts_sent
      end
      def after_initialize
        # overrideable hook for updating message
      end
      def after_create
        # overrideable hook for updating message
      end
      def model
        ContactMessage
      end
      def message_params
        params.require(:contact_message).permit(RocketCMS.config.contacts_fields.keys + [:name, :email, :phone, :content, :captcha, :captcha_key])
      end
    end
  end
end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
rocket_cms-0.27.1 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.27.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.26.1 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.26.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.25.5 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.25.4 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.25.3 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.25.1 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.25.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.24.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.22.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.21.1 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.21.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.20.1 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.20.0 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.19.8 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.19.7 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.19.6 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.19.4 lib/rocket_cms/controllers/contacts.rb
rocket_cms-0.19.3 lib/rocket_cms/controllers/contacts.rb