Sha256: 7aa177ec6430ca8d47125ac8ab92f1f9810591ffebb67add1dc2550d666079c6

Contents?: true

Size: 1.07 KB

Versions: 61

Compression:

Stored size: 1.07 KB

Contents

module MinimumViableProduct
  module SessionConcern
    extend ActiveSupport::Concern

    COOKIE_ID = '_session'

    included do
      helper_method :current_user
    end

    def sign_in(user)
      session[COOKIE_ID] = user.id
    end

    def current_user
      @current_user ||= begin
                          if session[COOKIE_ID]
                            Conversion.find(session[COOKIE_ID])
                          end
                        rescue ActiveRecord::RecordNotFound
                          session[COOKIE_ID] = nil
                        end
    end

    # http://blog.laaz.org/tech/2012/12/27/rails-redirect_back_or_default/
    def store_location
      session[:return_to] = if request.get?
        request.url
      else
        request.referer
      end
    end

    # http://blog.laaz.org/tech/2012/12/27/rails-redirect_back_or_default/
    def redirect_back_or_default(default = root_url)
      redirect_to(session.delete(:return_to) || request.referer || default)
    end
    alias_method :redirect_to_back_or_default, :redirect_back_or_default
  end
end

Version data entries

61 entries across 60 versions & 2 rubygems

Version Path
minimum_viable_product-0.5.2 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.5.1 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.5.0 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.4.4 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.4.3 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.4.2 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.4.1 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.4.0 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.3.4 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.3.3 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.3.2 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.3.1 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.3.0 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.7 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.6 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.5 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.4 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.3 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.2 app/controllers/concerns/minimum_viable_product/session_concern.rb
minimum_viable_product-0.2.1 app/controllers/concerns/minimum_viable_product/session_concern.rb