2

目前我正在使用设计开发一个简单的 Rails 3 Web 应用程序。当用户注册时,Account会创建一个。这是 Account 模型的本质:

class Account < ActiveRecord::Base
  include Authority::UserAbilities

  # Callbacks
  after_create do |account|
      account.create_person
      account.add_role :owner, account.person
  end

  has_one :person, dependent: :destroy
end

以及 Person 模型的精髓:

class Person < ActiveRecord::Base
  belongs_to :account
  default_scope where(published: true)
end

如您所见,一个人(基本上是一个用户配置文件)是在创建帐户后创建的,默认published值为false. 注册后,用户登录并重定向到主页,其中包含edit_person_path(current_account.person).

在设置了default_scopefor Person aRouting Error: No route matches {:action=>"edit", :controller=>"people", :id=>nil}后,由于edit_person_path(current_account.person).

我对此的解决方案是更改edit_person_path(current_account.person)edit_person_path(Person.unscoped { current_account.person} ).

我现在遇到的问题是,尽管页面渲染得很好,但是当我单击编辑链接时,会引发以下异常:

ActiveRecord::RecordNotFound in PeopleController#edit
Couldn't find Person with id=126 [WHERE "people"."published" = 't']

暂时取消编辑操作范围的最佳方法是什么,我应该这样做PeopleController#edit吗?

4

0 回答 0