【发布时间】:2011-02-15 16:45:12
【问题描述】:
我已经设置了 Devise 需要的所有东西。对我来说一切都很好。
但是有一件事情很烦人:
当我通过浏览器(Firefox)请求需要身份验证的页面时,它只会弹出一个警告对话框:
"A username and password are being requested by http://localhost:3001. The site says: "Application"'
使用用户名和密码输入字段,而不是重定向到登录页面(“/users/sign_in”页面)。但是,即使我输入了任何用户名和密码,我也无法访问(我可以使用相同的信息通过“/users/sign_in”成功登录)。
请帮忙:(
更新我的模型:
class Account < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
我的控制器(从脚手架生成):
class ThingsController < ApplicationController
before_filter :authenticate_account!, :except => ['show', 'index']
# GET /things
# GET /things.xml
def index
@things = Thing.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @things }
end
end
# GET /things/1
# GET /things/1.xml
def show
@thing = Thing.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @thing }
end
end
# GET /things/new
# GET /things/new.xml
def new
@thing = Thing.new
....
如果您需要更多信息,请告诉我:)
【问题讨论】:
-
您似乎已启用基本身份验证。我没有足够的设计来给你一个关于如何禁用它的提示。
-
谢谢Augusto,几乎解决了这个问题。我搜索了一下,但仍然没有找到完美的解决方案,但找到了这个:ewout.name/2010/04/http-basic-authentication-with-devise 但是出现了新的错误:“未初始化的常量 Devise::Strategies::HttpAuthenticatable (NameError)”
-
你能用你的用户模型更新问题吗?你使用设计:database_authenticable?
-
感谢 StefanS,我已经更新了帖子 :)
标签: ruby-on-rails plugins gem devise authentication