Form_for submit
I have 2 models, say Model A and Model B, each one having certain fields (a1,a2,a3) and (b1,b2,b3).
I ran the scaffold command to generate the controllers and views for the models. Now, What i want to do is: -On the new page of model A, I want to add a button/ href lin to create a new B o开发者_StackOverflow中文版bject.
When the user clicks the button, a div appears below which has a form for creating B object. When the user clicks the submit button after filling in the details for model B object, the changes are saved to the DB directly.
NOTE : A and B are not related to each other. Can someone suggest me a way to do so??
Take a look at the screencasts listed below from the incomparable Railscasts series if you haven't already watched then. They pretty much cover all the basics of processing multiple models on a singe form
- Nested Model Form Part 1
- Nested Model Form Part 2
To display a <div>
's contents when a button/link is clicked can be easily done in Javascript with JQuery (for example). That is described in the examples here.
精彩评论