I’m trying a basic user authorization with CanCan and for some reason the already logged in user, after submitting an update on their profile, devise is signing out.
I can’t figure out, why this is happening.
My ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
can [:welcome, :read, :create, :new], User
if user.role == 'member'
can :manage, User, :id => user.id
end
end
end
And my update method from UsersController
def update
if @user.update_attributes(params[:user])
flash[:success] = "Profile saved!"
#sign_in @user // tried this with no lucky, it still signing out
redirect_to @user
else
render 'edit'
end
end
As you can see, it’s pretty basic.
The flash message is showing up and the redirect also is working as expected.
Any idea?
I have forgot to add
before_filter :authenticate_user!to myUsersControllerIt’s now working. Thanks