2012-03-19 67 views

回答

0

我对你的问题有点不清楚。如果您只想知道给定用户已登录,则在向新用户显示表单的控制器方法中,检查是否已设置current_user,如果是,请设置一条闪烁的消息。例如,在,也许registrations_controller.rb

# show an empty registration form to user 
def new 
    if current_user 
    flash[:notice] = "Hey #{current_user.name}, you're already logged in!" 
    return 
    end 
    ... rest of normal controller code to create a registration form 
end 

如果你想防止非管理员用户创建新用户,你需要检查自己的角色,例如

unless current_user.has_role? :superadmin 
    flash[:warning] = "Sorry #{current_user.name}, I can't do that for you." 
    return 
end 
相关问题