Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Unable to get the values of the application constants from the constants defined in the environment.rb (or application.rb) for the authorization plugin in rails3 #4

Open
PratikNarkar opened this issue Dec 13, 2010 · 1 comment

Comments

@PratikNarkar
Copy link

I have defined following constants in the config/application.rb present inside my rails3 application which are required for authorization plugin (used for access control)
AUTHORIZATION_MIXIN = "object roles"
LOGIN_REQUIRED_REDIRECTION = { :controller => '/homes', :action => 'index' }
PERMISSION_DENIED_REDIRECTION = {:controller => '/homes', :action => 'new'}
These constants added in the rails3 application's application.rb (or environment.rb) are not accessible inside the authorization plugin

@PratikNarkar
Copy link
Author

In rails3
irb(main):007:0> h = {a:1, b:'2', c:6 }
=> {:a=>1, :b=>"2", :c=>6}
irb(main):008:0> h.keys
=> [:a, :b, :c]
irb(main):009:0> h.keys.include? 'b'
=> false
irb(main):010:0> h.keys.include? :b
=> true

Solution:
Authorization plugin checks
if not Object.constants.include? "LOGIN_REQUIRED_REDIRECTION"

but in rails3 Object.constants returns array of symbols i.e. [:Object, :Module, :Class, :Kernel, :LOGIN_REQUIRED_REDIRECTION, :PERMISSION_DENIED_REDIRECTION, ...]
while previously (in rails 2.x) it was returning array of strings
Thus, Object.constants.include? "LOGIN_REQUIRED_REDIRECTION" returns false even if constant is present

To avoid this and to make the constants accessible from authorization plugin in rails3 application, we need to add the application constants to
config/application.rb file and change the constant in the string to symbol
i.e do following changes in the rails-authorization-plugin/lib/authorization.rb file
if not Object.constants.include? "LOGIN_REQUIRED_REDIRECTION" to if not Object.constants.include? :LOGIN_REQUIRED_REDIRECTION
if not Object.constants.include? "PERMISSION_DENIED_REDIRECTION" to if not Object.constants.include? :PERMISSION_DENIED_REDIRECTION
if not Object.constants.include? "STORE_LOCATION_METHOD" to if not Object.constants.include? :STORE_LOCATION_METHOD

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant