:請求書レコードにRails - シングルユーザー複数の "ロール?"ユーザーに属する請求書のモデル、および特定の役割または複数の役割として、ユーザを関連付けるユーザテーブル持っ
class CreateInvoices < ActiveRecord::Migration
def self.up
create_table :invoices do |t|
t.string :po_number
t.datetime :invoice_date
t.datetime :date_received
t.datetime :date_approved
t.text :clerk_note
t.integer :clerk_id
t.integer :approver_id
t.text :approver_note
end
end
class Invoice < ActiveRecord::Base
belongs_to :user
end
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :first_name
t.string :last_name
t.string :username
t.string :email
t.boolean :account_clerk
t.boolean :approver
t.boolean :admin
end
end
class User < ActiveRecord::Base
has_many :invoices
end
を、どのように私は依存clerk_idとapprover_idを割り当ててくださいロールはユーザモデルに設定されていますか?各請求書には書記官と承認者が含まれますが、どちらもユーザーです。
同様に、clerk_noteをclerk_idに、approver_noteをapprover_idに割り当てるにはどうすればよいですか?この場合、私はcurrent_userを参照することができます。なぜなら、ログインしたユーザーはメモを作成するユーザーになるからです。
これは私のグーグルでは、私は何を探すべきかわからなかった...あなたの助けを前もって感謝します。
は、あなたが実際に請求書テーブルから店員と承認者の列を分割し、次の列がありinvoice_usersテーブルを作成することができます。同じユーザーがシステムの承認者と書類係になることができるかどうかは不明です。 –
そのアイデアをお寄せいただきありがとうございます - はい、ユーザーは承認者/係員のどちらかまたは両方になることができます。私はこのアプローチを使用するかもしれません...ありがとう。 –