레일 보안 주제에 관심이 있으며 Security on Rails을 사용하고 있습니다. RBAC 구현/142 페이지에 있습니다. 그리고 주제의 오류를 지나칠 수 없습니다. 다음 예외기대하지 않았을 때 객체가 없습니다.
module RoleBasedControllerAuthorization
def self.included(base)
base.extend(AuthorizationClassMethods)
end
def authorization_filter
user = User.find(:first,
:conditions => ["id = ?", session[:user_id]])
action_name = request.parameters[:action].to_sym
action_roles = self.class.access_list[action_name]
if action_roles.nil?
logger.error "You must provide a roles declaration\
or add skip_before_filter :authorization_filter to\
the beginning of #{self}."
redirect_to :controller => 'root', :action => 'index'
return false
elsif action_roles.include? user.role.name.to_sym
return true
else
logger.info "#{user.user_name} (role: #{user.role.name}) attempted to access\
#{self.class}##{action_name} without the proper permissions."
flash[:notice] = "Not authorized!"
redirect_to :controller => 'root', :action => 'index'
return false
end
end
end
module AuthorizationClassMethods
def self.extended(base)
class << base
@access_list = {}
attr_reader :access_list
end
end
def roles(*roles)
@roles = roles
end
def method_added(method)
logger.debug "#{caller[0].inspect}"
logger.debug "#{method.inspect}"
@access_list[method] = @roles
end
end
그리고 @access_list [방법] = @roles 광고 송구 : I가 레일 3.0.3 및 1.9.2 루비 사용하고
ActionController::RoutingError (You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]=):
app/security/role_based_controller_authorization.rb:66:in `method_added'
app/controllers/application_controller.rb:5:in `<class:ApplicationController>'
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/home_controller.rb:1:in `<top (required)>'
여기서 코드이다. 데이터베이스에 세션을 저장하고 있습니다. 마침내 모든 조언에 감사드립니다.
로 캉캉을 확인 할 수 있습니다. 최신 버전에서는 두 가지 모두에서 매우 중요한 변화가있었습니다. 그 콤보를 실행하고 여전히 문제가 있는지 확인하려고합니다. RVM을 사용한다면 레일과 루비 버전을 정말 빨리 전환 할 수 있습니다. – rwilliams
확인. 나는 RVM을 사용하고있다. 하지만 Rails 3과 Ruby 1.9.2에서 필요합니다. 도와주세요? – Zeck
예외 백 트레이스를 추가 할 때 알 수 없기 때문에 예외 행이 무엇인지에 대해 적어도 일부 행 번호를 표시해보십시오. – Nakilon