嘿傢伙我創建了一些自定義身份驗證感謝railscasts.com但我有點卡住,因爲我需要限制我的用戶編輯其他用戶的配置文件。需要幫助自定義身份驗證
這裏是我的authenticate_user和CURRENT_USER方法:
private
def current_user
@current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
end
def authenticate_user!
if current_user.nil?
redirect_to login_url, :alert => "You must first log in to access this page"
end
end
下面是我的UsersController的的before_filter:
before_filter :authenticate_user!, :only => [:edit, :update, :destroy]`
編輯:固定它歸功於alock27。
我不得不修改我的users_controller和修改編輯動作如下:
@user = User.find(params[:id]
redirect_to root_url unless current_user == @user
你在使用Devise嗎? – efoo
不,它是一個使用railscasts.com的教程構建的自定義身份驗證系統:p – imjp