2

現在、私はdeviseを使用して単純なRails 3 Webアプリケーションに取り組んでいます。ユーザーがサインアップすると、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 を設定した後、Routing Error: No route matches {:action=>"edit", :controller=>"people", :id=>nil}が原因で a がスローされました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