Я реализовал аутентификацию с помощью устройства devise и управляю ролями с помощью CanCan. Мое приложение управляет Рецептами, и когда я уничтожаю Рецепт, я закрываю сессию и перенаправляю меня в представление sign_in ...
Если я не проверяю аутентификацию и разрешения (см. Recipes_controller выше), все работает нормально.
Это очень странно, и я понятия не имею, почему это происходит. Пожалуйста, помогите.
Спасибо
LOG
Started POST "/recipes/21" for 127.0.0.1 at Thu Dec 08 19:53:30 +0100 2011
Processing by RecipesController#destroy as HTML
Parameters: {"id"=>"21"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 5 LIMIT 1
Completed 401 Unauthorized in 44ms
Started GET "/users/sign_in" for 127.0.0.1 at Thu Dec 08 19:53:30 +0100 2011
Processing by Devise::SessionsController#new as HTML
Rendered devise/shared/_links.erb (2.5ms)
Rendered devise/sessions/new.html.erb within layouts/application (14.2ms)
Completed 200 OK in 52ms (Views: 20.8ms | ActiveRecord: 0.0ms)
RECIPES_CONTROLLER:
class RecipesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
def destroy
@recipe = Recipe.find(params[:id])
@recipe.destroy
redirect_to recipes_url, :notice => "Successfully destroyed Recipe."
end
СПОСОБНОСТЬ:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role? :super_admin
can :manage, :all
else if user.role? :super_read_admin
can :read, :all
else
# manage reciped he owns
can :manage, Recipe do |recipe|
recipe.owner == user
end
end
end
end
end