Если вам не безразличны скаффолдинг, я бы посоветовал вам создать эшафот для транзакций
: script/generate scaffold transaction financial_id:integer ...
bank_accounts: script/generate scaffold bank_account financial_id:integer ...
и финансовых показателейscript/generate scaffold financials ...
Добавьте в свою модель транзакций следующее:
class Transaction < ActiveRecord::Base
belongs_to :financial
end
Добавьте в свою модель bank_account следующее:
class Bank_account < ActiveRecord::Base
belongs_to :financial
end
Добавьте в свою финансовую модель:
class Financial < ActiveRecord::Base
has_many :transactions
has_many :bank_accounts
end
Теперь из вашего финансового диспетчера вы можете использовать что-то вроде этого:
def index
@financial = Financial.find(params[:id])
#This fetches all bank_accounts related to financial
@bank_accounts = @financial.bank_accounts
#This fetches all transactions related to financial
@transactions = @financial.transactions
end
В ваших представлениях вы можете просматривать все банковские счета, принадлежащие определенному финансовому инструменту, просто делая это:
<% @bank_accounts.each do |bank_account| -%>
<%=h bank_account.something_here %> <!-- something_here is the column name corresponding to your bank_account table. -->
<%=h bank_account.something_here %> <!-- something_here is the column name corresponding to your bank_account table. -->
<%=h bank_account.something_here %> <!-- something_here is the column name corresponding to your bank_account table. -->
.
.
.
<% end -%>
В своих представлениях вы можете просмотреть все транзакции, относящиеся к определенному финансовому документу, добавив что-то похожее:
<% @transactions.each do |transaction| -%>
<%=h transaction.something_here %> <!-- something_here is the column name corresponding to your bank_account table. -->
<%=h transaction.something_here %> <!-- something_here is the column name corresponding to your bank_account table. -->
<%=h transaction.something_here %> <!-- something_here is the column name corresponding to your bank_account table. -->
.
.
.
<% end -%>
Помните, что при создании новой транзакции / банковского счета используйте идентификаторпринадлежность к конкретному финансовому.Надеюсь это поможет.Ура!:)