You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I have a feeling I'm attempting something unconventional, so I figured I would create this post to see if someone is willing to recommend a better solution.
I have a show action that renders a a collection of items that user can interact with. Each item is wrapped in a form to allow the user to update attributes of each item. The reason for this is to try and consolidate editing multiple items into one area instead of requiring the user to edit each one individually. Each form has an associated data-turbo-command and works as expected from the show view.
While the above works, what I'd ideally like to do is allow the user to get see this show view and edit these items while sitting on an index view via a modal. I'm currently rendering a modal UI into the application layout with a turbo-frame with an id of modal. I then have a link in the index table that points to the show action and targets the modal turbo-frame. The show action renders with the matching turbo-frame and the modal appears without issue.
However, when an edit is performed inside the modal, the command triggers as expected, but a CSRF error is raised and the command doesn't run. I know this is related to a new token being generated with the show action runs. I've attempted to change the show action to not render the application layout when the request happens from the index action, but the issue I run into there is that the edit actions inside the modal are then targeted at the index action, and not the show action so the command isn't able to know what item from the index action is being edited.
Is there a better way to accomplish what I'm trying to do? Thanks in advance!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello! I have a feeling I'm attempting something unconventional, so I figured I would create this post to see if someone is willing to recommend a better solution.
I have a show action that renders a a collection of items that user can interact with. Each item is wrapped in a form to allow the user to update attributes of each item. The reason for this is to try and consolidate editing multiple items into one area instead of requiring the user to edit each one individually. Each form has an associated
data-turbo-command
and works as expected from the show view.While the above works, what I'd ideally like to do is allow the user to get see this show view and edit these items while sitting on an index view via a modal. I'm currently rendering a modal UI into the application layout with a
turbo-frame
with an id ofmodal
. I then have a link in the index table that points to the show action and targets the modal turbo-frame. The show action renders with the matching turbo-frame and the modal appears without issue.However, when an edit is performed inside the modal, the command triggers as expected, but a CSRF error is raised and the command doesn't run. I know this is related to a new token being generated with the show action runs. I've attempted to change the show action to not render the application layout when the request happens from the index action, but the issue I run into there is that the edit actions inside the modal are then targeted at the index action, and not the show action so the command isn't able to know what item from the index action is being edited.
Is there a better way to accomplish what I'm trying to do? Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions