Reputation: 5892
Pretty stumped at the moment trying to figure something out. I have a modal that shows a table, and for each of the entries in the table, I have actions (i.e., show, edit, delete, etc). When the user clicks on "Edit" for an entry row in this model, I want it to populate another model with a form to show the data associated with that entry.
Is there a convenient way to do this? For one, I do not know how to pass a parameter to a modal from another modal. I don't know how to make this form "reinitialize" after it's already been rendered when the first page is loaded.
Any suggestions?
Upvotes: 0
Views: 627
Reputation: 1008
I have been in the same situation and I suggest that you just keep the one modal and replace the contents through AJAX (IMO). Once you have rendered into the modal in the first place, your links can then just render as AJAX the same way that they would and overwrite the information inside the modal. The way I did it was this:
= link_to "Text", "url", remote: true
(let's say this is the edit action).edit.js.erb
file would contain one line: $('#Modal_content').html("<%= j render 'edit' %>")
(#Modal_content is just a div that I put in my modal so that I can replace all the contents without messing up the close button and other modal required html)._edit.html.erb
file is called where you would put all of what you needed that comes from the edit action.As for passing information, the id is passed through the link that you click on to call the controller#edit action.
Let me know if you need more details, but that should get you most of the way there.
Upvotes: 1