Sha256: 74e11de83cf606e3d4394d2f4b9f459d581e697b38c89e872d4c91b89a1a74c4

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

module MVP
  module SessionConcern
    extend ActiveSupport::Concern

    COOKIE_ID = '_session'

    included do
      helper_method :current_user
    end

    def current_user=(user)
      session[COOKIE_ID] = user.id
    end
    alias_method :sign_in, :current_user=

    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(path=nil)
      session[:return_to] = case
                            when !path.nil?
                              path
                            when 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=nil)
      redirect_to(session.delete(:return_to) || default || request.referer)
    end
    alias_method :redirect_to_back_or_default, :redirect_back_or_default
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mvpkit-1.1.0 app/controllers/concerns/mvp/session_concern.rb
mvpkit-1.0.4 app/controllers/concerns/mvp/session_concern.rb
mvpkit-1.0.3 app/controllers/concerns/mvp/session_concern.rb
mvpkit-1.0.2 app/controllers/concerns/mvp/session_concern.rb
mvpkit-1.0.1 app/controllers/concerns/mvp/session_concern.rb
mvpkit-1.0.0 app/controllers/concerns/mvp/session_concern.rb
mvpkit-0.8.1 app/controllers/concerns/mvp/session_concern.rb
mvpkit-0.8.0 app/controllers/concerns/mvp/session_concern.rb