0

我需要在我们正在构建的 rails 应用程序中实现基于角色的访问。用户和角色信息位于不同的数据库中。现在可以通过调用服务来获得用户的授权资源。我需要关于如何在后端实现这一点的建议。UI 是 javascript 繁重的应用程序。

用户的角色信息也可作为服务使用。我的想法是调用它并在后端定义规则。如果你们能指出我的方向,那就太好了。

谢谢拉米亚

4

1 回答 1

0

If I were you, I think I would add recordless models in app and incapsulate service calls in these models, so that it behaves as usual Rails model.

class User
  def self.find_by(*args)
    params_to_get_instance = #some service call with *args
    new(parmas_to_get_instance)
  end

  def role
    @role = #some service call ommited
  end
end 

You can also take a look for modules (http://api.rubyonrails.org/classes/ActiveModel.html) which you can include in your model to get familiar ActiveRecord functionality. For example ActiveModel::Validations, ::Callbacks and so on.

于 2013-06-01T07:47:37.027 回答