Sha256: adbfbaf5d3d7fbdd4e2ef4640e9201b5debd254377e41c2ea604b303e960c6ec

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

# frozen_string_literal: true

class SubscribersController < ApplicationController
  respond_to :js, only: :create

  def create
    @subscriber = SubscribeForm.new(subscriber_params)
    @subscriber.valid? && @subscriber.submit

    params[:from] ||= params[:subscriber][:from]

    respond_to do |format|
      format.js  { render }
      format.all { redirect_to(root_path) }
    end
  end

  def show
    if params[:confirmation_token].present?
      subscribe!
      respond_with @subscriber
    else
      render_404
    end
  end

  private

  def subscribe!
    @subscriber = SubscribeForm.confirm!(params[:confirmation_token])
    @structure = if @subscriber.errors.blank?
                   ContentStorageType.subscribe_success.storage
                 else
                   ContentStorageType.subscribe_fail.storage
                 end
    @text = @structure.content!
  end

  def subscriber_params
    params.require(:subscriber).permit(:email, :category_id)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/controllers/subscribers_controller.rb