My web app, up until this point, has been fairly straight forward. I have Users, Contacts, Appointments and a few other things to manage. All of these are easy – it’s just one model per section so I just did a scaffold for each, then modified the scaffolded code to fit my need. Pretty easy…
Unfortunately I am having a problem on this next section because I want the ‘Financials’ section of my app to be more in depth than the other sections which I simply scaffolded. For example, when the user clicks the ‘Contacts’ link on the navigation bar, it just shows a list of contacts, pretty straight forward and is in line with the scaffold. However, when the user clicks the ‘Financials’ link on the navigation bar, I want to show the bank accounts on the left of the page and a few of the transactions on the right.
So the financials tab will basically work with data from two models: transactions and bank_accounts. I think I should make the models (transactions & bank_accounts) and then make a controller called Financials, then I can query the models from the Financials controller and display the pages in app/views/financials/
Am I correct in this app layout? I have never worked with more than the basics of scaffolding so I want to ensure I get this right!
Thank you!
If you are comfortable with scaffolding then i would suggest that you generate a scaffold for both
transactions:
script/generate scaffold transaction financial_id:integer ...bank_accounts:
script/generate scaffold bank_account financial_id:integer ...and financials
script/generate scaffold financials ...In your transactions model, add this:
In your bank_account model, add this:
In your financial model, add this:
Now from your financials controller you can use something like this:
In your views you can view all the bank accounts belonging to a particular financial by just doing this:
In your views you can view all the transactions belonging to a particular financial by adding something similar:
Remember, while creating a new transaction/bankaccount use the id belonging to the particular financial. Hope this helps. Cheers! 🙂