Sha256: cac3d4adc9d661ae4f1c56a204cc80efde4b7fb5292d3ecf8e3b43da4fbac8f0

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require_dependency "astrochimp/application_controller"

module Astrochimp
  class SignupsController < ApplicationController
    before_filter :capture_referrer_code, only: [:index]

    def capture_referrer_code
      session[:referrer_id] = Signup.code_to_id(params[:referrer_code]) if params.has_key? :referrer_code
    end

    # User's 'astrochimp_splash' layout in THEIR app (that uses this gem)
    layout "#{Rails.root}/app/views/layouts/#{ENV['AC_SPLASH_LAYOUT'] || 'astrochimp_splash'}"

    def index
      @signup = Signup.new

      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @signup }
      end
    end

    def show
      @signup = Signup.find(params[:id])
    end

    # POST
    def create
      @signup = Signup.new(params[:signup].merge(referrer_id: session[:referrer_id]))
      @signup.status = Signup::STATUS_NEW

      respond_to do |format|
        @signup.save
        if @signup.errors.any?
          format.html { render action: :index }
          format.json { render json: @signup.errors, status: :unprocessable_entity }
        else
          SignupMailer.signup_complete(@signup).deliver
          format.html do
            flash[:signup_success] = ENV['AC_SIGNUP_SUCCESS_NOTICE']
            redirect_to @signup, notice: ENV['AC_SIGNUP_SUCCESS_NOTICE']
          end
          format.json { render json: @signup, status: :created, location: @signup }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
astrochimp-0.2.5 app/controllers/astrochimp/signups_controller.rb