English 中文(简体)
与用户或行政模型和基文风格亚库曼一道开发标识
原标题:Devise login with user or admin models and Basecamp style subdomains

我有单独的发展用户和管理模式。 我也使用“基地”风格的子宫。 除少数控制者和我需要能够认证用户或行政的行动外,所有工作都是良好的。

目前,我已经认证了用户。 我的申请“控制员”中确定,我正在用天空来绕过它。

不幸的是,我不能简单地具体说明对每个控制员的认证要求,因为我仍然需要一些控制人员,并采取行动让用户或代理人都能进入。

我曾尝试过几件事,但没有结果。 看来,如果我搬走真的——用户! 和认证——行政! 它未加工成某种次主要探测逻辑。 基本:

current_subdomain = request.subdomains.first    
if current_subdomain ==  admin 
 authenticate_admin!
else
 authenticate_user!
end

在某个时候,我得以尝试认证,但出于某种原因,它未能将届会控制者排除在需要认证之外,从而导致重新定位(首先对我来说是同Ruby!)。

我认识到,我可以给我的用户增加一个表明行政地位的领域,但申请要求使用者与阿明人之间更大程度的权力分立,只有少数控制者和行动除外。

  • Ruby 1.9.2
  • Rails 3.0.3
  • Devise 1.1.3
最佳回答

在按照电线进行过滤之前写自己的字

#application_controller.rb
def authenticate_any!
    if admin_signed_in?
        true
    else
        authenticate_user!
    end
end

当时,在控制器里,你要求行政管理人员和用户都能够通过认证使用获得服务。

#myobject_controller.rb
before_filter :authenticate_any!

如果你被拖入一个行政大楼,那么你会通过之前的过滤器,否则你会通过真正的用户! 这是违约行为。

问题回答

实际上,这种工作没有:

#application_controller.rb
def authenticate_any!
    if admin_signed_in?
        true
    else
        authenticate_user!
    end
end

它将开始对真实用户进行无限的再保险。

try this instead:

def authenticate_user!
  return if admin_signed_in?
  super
end

Just remember that with this second solution you re saying something like this: You must be logged in as, at least, user and you will lose the authentication of users only.

排雷人员将能够接触到所有东西。

或许你们应考虑增加一杯子——Can可以处理角色

Quite nice described here: http://www.tonyamoyal.com/2010/09/29/rails-authentication-with-devise-and-cancan-part-2-restful-resources-for-administrators/





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签