Sha256: 4634ee7d085a4b8788a788af441577575a502a0aba802b84567a845d1acd0eea

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  require 'action_view_helper'
  require 'application_csv'

  before_filter :authorize

  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password

#  rescue_from Exception, :with => :error

protected
  def error(e)
    logger.error(e.message);
    flash[:error] = t(:error_default, :message => e)
    begin
      if action_name == :index.to_s
        reset_session
        redirect_to(login_url)
        return
      end
      redirect_to(:action => :index)
    rescue
      redirect_to(top_url)
    end
  end

  def authorize
    begin
      session_check
      @user = User.find(session_get_user)
      raise unless @user
      @app_search = ApplicationSearch.new(params) if action_name == :index.to_s
    rescue => e
      logger.debug(e.message)
      flash[:notice] = t(:error_authorize)
      redirect_to(root_url)
    end
  end

  def session_reset
    session[:user_id] = nil
    session[:ids]     = nil
    session[:prm]     = nil
    session[:msg_opn] = nil
    reset_session
  end

  def session_check
    raise unless session[:user_id]
  end

  def session_get_user
    return session[:user_id]
  end

  def session_get_ids
    return session[:ids]
  end

  def session_get_prm
    return session[:prm]
  end

  def session_get_msg_opn
    return session[:msg_opn]
  end

  def session_set_user(user)
    session[:user_id] = user.id
  end

  def session_set_ids(objs)
#    return unless params[:format].to_s == :html.to_s
    ids = Array.new(objs.size)
    session[:ids] = ids
    session[:prm] = params
  end

  def session_set_msg_opn(msg_opn)
    session[:msg_opn] = msg_opn
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ava_rails_generator-0.0.3 templates/application_controller.rb
ava_rails_generator-0.0.2 templates/application_controller.rb