Sha256: cfca2091eb2a6a7ec69896a4174ccb17b74c74cae0ce45eeb470da48384bf037

Contents?: true

Size: 1.54 KB

Versions: 38

Compression:

Stored size: 1.54 KB

Contents

module IuguSDK
  module Controllers
    module Helpers
      extend ActiveSupport::Concern

      def search_user_account( account_id )
        return false unless signed_in? and current_user
        current_user.account_users.where( :account_id => account_id ).try(:first)
      end

      def current_user_account
        @current_user_account ||= search_user_account( session[:current_account_id] )
      end

      def current_account
        current_user_account.try(:account)
      end

      def set_account( resource, account_id=nil )
        if account_id == nil
          account_id = cookies[:last_used_account_id] if cookies[:last_used_account_id]
        end
        selected_account = resource.default_account( account_id )
        if selected_account
          cookies[:last_used_account_id] = { :value => selected_account.id, :expires => 365.days.from_now }
          session[ :current_account_id ] = selected_account.id
        end
        selected_account
      end

      def is_active?(control, action="", id="")
        if id == ""
          if action == ""
            return true if controller_name == control.gsub("/", "")
          else
            return true if controller_name == control.gsub("/", "") && action_name == action
          end
        else
          return true if controller_name == control.gsub("/", "") && action_name == action && id == params[:id]
        end
        return false
      end

      def body_classes
        [controller_name,action_name,'page-' + controller_name + '-' + action_name]
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
iugusdk-1.0.11 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.10 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.9 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.8 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.7 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.6 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.5 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.4 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.3 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.2 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.1 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.32 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.31 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.30 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.29 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.28 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.27 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.26 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.25 lib/iugusdk/controllers/helpers.rb
iugusdk-1.0.0.alpha.24 lib/iugusdk/controllers/helpers.rb