Sha256: 97077eb09ae2397159dd8f31a2e72c6f296daf7227b225ee37920cc1c1d4c6af

Contents?: true

Size: 1.46 KB

Versions: 35

Compression:

Stored size: 1.46 KB

Contents

module Cmor
  module Contact
    class ContactRequestsController < Cmor::Contact::Configuration.base_controller.constantize
      before_action :initialize_resource, only: [:index, :new]
      before_action :initialize_resource_for_create, only: [:create]

      respond_to :html
      responders :flash

      def self.resource_class
        Cmor::Contact::ContactRequest
      end

      def index
        new
        render :new
      end

      def new; end

      def create
        @resource.ip_address = request.remote_ip
        if @resource.save
          respond_with @resource, location: after_create_url
        else
          respond_with @resource
        end
      end

      private

      def initialize_resource_for_create
        @resource = initialize_scope.new(permitted_params)
      end

      def initialize_resource
        @resource = initialize_scope.new
      end

      def initialize_scope
        resource_class
      end

      def resource_class
        self.class.resource_class
      end

      def permitted_params
        # Allow only available attributes and add nickname for spam protection.
        attrs = (
          resource_class.attribute_names.map(&:to_sym) & [:nickname, :name, :email, :phone, :subject, :message, :accept_terms_of_service]
        ) + [:nickname]
        params.require(:contact_request).permit(attrs)
      end

      def after_create_url
        Cmor::Contact::Configuration.after_create_url.call(self)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
cmor_contact-0.0.60.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.59.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.58.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.57.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.56.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.55.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.54.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.53.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.52.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.51.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.50.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.49.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.48.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.45.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.44.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.43.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.42.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.41.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.40.pre app/controllers/cmor/contact/contact_requests_controller.rb
cmor_contact-0.0.39.pre app/controllers/cmor/contact/contact_requests_controller.rb