我有两个ROR3应用程序:

  • http://users.domain.local
  • http://profiles.domain.local

我创建了“用户/模型/profile.rb”:

class Profile < ActiveResource::Base
  self.site = "http://profiles.domain.local"
end

在“ profiles/models/profile.rb”中,我有:

attr_accessible :name

我的个人资料的SQL表包含以下列:

  • ID
  • 姓名
  • 用户身份

所以如果我跑步 Profile.create(:name => "test_name") 将在 http://profiles.domain.local 带有“ test_name”的名称。

出于明显的安全原因,我不想使'user_id'属性访问,但是我需要在配置文件创建中设置该属性 从“用户”应用程序.

我尝试了很多方法,但是找不到简单的解决方案。也许,有可能 if 在填写“用户”应用程序的请求的“配置文件”应用程序的“ attr_accessible”附近的语句。

有人可以帮我吗?

有帮助吗?

解决方案

您可以尝试类似Amazon Web服务所做的事情:在每个请求中使用非常长的随机生成的密钥。检查该密钥在您的配置文件应用程序中是正确的,如果是,请更新属性。

其他提示

解决方案:不要简单地使用 Profile.create, ,改用协会构建者。保护 user_id 属性和使用 user.profiles.create!(params[:profile]) 使它自动设置 user_id 概况的字段到任何 user 对象是。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top