(聲明:我是很新的軌道)declarative_authorization和authlogic問題
這個插件看起來這將是我的應用程序非常適合,但我 有一個很難得到它的工作。我使用它與authlogic,我不知道這是否是問題,但它似乎可能是。
當我嘗試訪問我的管理員角色應該可以訪問我 得到這個頁面:
Processing CompaniesController#show (for 127.0.0.1 at 2010-02-12
23:26:44) [GET]
Parameters: {"action"=>"show", "id"=>"1", "controller"=>"companies",
"battalion_id"=>"1"}
User Load (0.000681) SELECT * FROM "users" WHERE ("users"."id" =
'147') LIMIT 1
User Update (0.000622) UPDATE "users" SET "perishable_token" =
'tUyTl1eZDQSJwp_PFw7c', "last_request_at" = '2010-02-13 05:26:44',
"updated_at" = '2010-02-13 05:26:44' WHERE "id" = 147
Role Load (0.000334) SELECT * FROM "roles" WHERE ("roles".user_id
= 147)
Permission denied: No matching rules found for show for #<User id:
147, user_type: nil, login: "lauren_roth", name: "Lauren
Rothlisberger", email: "[email protected]",
crypted_password:
"d835a2cdf15ef449d0980e706fd86d7a9a7a0a23d0d79d6f18f...",
password_salt: "_Qz_z8eZOhKHcsPsBsoP", created_at: "2010-02-12
16:37:53", updated_at: "2010-02-13 05:26:44", old_remember_token: nil,
old_remember_token_expires_at: nil, old_activation_code: nil,
activated_at: nil, old_password_reset_code: nil, enabled: true,
identity_url: nil, invitation_id: nil, invitation_limit: nil,
position: "Admin", battalion_id: nil, company_id: nil, soldier_id:
nil, login_count: 68, failed_login_count: 0, last_request_at:
"2010-02-13 05:26:44", current_login_at: "2010-02-13 05:20:59",
last_login_at: "2010-02-13 05:19:57", current_login_ip: "127.0.0.1",
last_login_ip: "127.0.0.1", persistence_token:
"28fc9b60853045cd4e43a001b4258940a7e8f9ac50b08df6a6d...",
single_access_token: "bKgYvuRtLqauufljZDoV", perishable_token:
"tUyTl1eZDQSJwp_PFw7c", active: true, platoon_id: nil> (roles
[:Admin], privileges [:show], context :companies).
Filter chain halted as [:filter_access_filter] rendered_or_redirected.
Completed in 27ms (View: 1, DB: 0 3 queries) | 403 Forbidden [http://
localhost/battalions/1/companies/1]
我有這個在我的用戶模型 高清role_symbols (角色|| [])。 map {| r | r.name.to_sym} end
但它似乎沒有調用。我認爲這可能是 問題的核心,但我也想知道是否有什麼要做 與user_sessions?
而且這是我application_controller是什麼樣子:
helper_method :current_user_session, :current_user
filter_parameter_logging :password, :password_confirmation
before_filter :set_current_user
protected
def set_current_user
Authorization.current_user = current_user
end
def current_user_session
return @current_user_session if defined? (@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
def store_location
session[:return_to] = request.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
Here is my authorization_rules.rb
我沒有利用管理,以反映:
authorization do
role :guest do
has_permission_on :user_sessions, :to => [:create, :update]
end
role :Admin do
has_permission_on :companies, :to => [:index, :show]
end
end
如果您有任何想法,我將不勝感激。謝謝。
是的,我可以看到我列出的最後一件事是authorization_rules和:Admin是大寫的,就像Role在Roles表中一樣。我似乎無法弄清楚哪裏出錯了。 – looloobs 2010-02-13 20:19:07