Hey everyone 
I have a weird use-case here and I’m not sure if it’s possible to do with Turbo alone.
I’d liek to be able to click a link which doesn’t have a data-turbo-frame
attribute, and server-side, in the Rails controller, do some computations and in some scenarios I want that request response to behave as a turbo-frame response.
So from the server side to tell it "respond as if the link had data-turbo-frame="some-frame"
, and on the client-side, Turbo would see that and interpret that response accordingly.
It would pick up just that frame’s content and replace it on the page.
Not sure if this can be achieved using just Rails, Turbo, and the turbo-rails gem.
Thank you!
To give a bit of context into why I’m asking.
I have a route which will only populate a modal through a turbo frame. Always and always.
And I’d like to be able to write the link without passing the data param. Not only me, but also my users.
link_to “Open modal”, modal_path
Hey there Adrian.
This post might have what you need: How to create Modals with Rails and Hotwire (and Tailwind CSS) | Rails Designer. Check the Force a view in a modal
section.
Good luck!
1 Like
From what I see this redirects to the root path if it’s not a turbo_frame request.
redirect_to root_path unless turbo_frame_request?
I need to mark that request as a turbo_frame request from the controller.
# pseudo code in the controller
before_action :force_turbo_frame_request, only: :new
This method does not exist AFAIK.
I tried to hack it by adding a turbo_frame_request_id
like the turbo-rails
gem uses, but it did not trick Rails into responding with a turbo_frame
.