Re link_to and response in controller

I am confused when using turbo in rails 6.1 when reading the development log. Using a Link_to method :get in side a turbo frame The logs said request.format = turbo-stream in rails 7.01 they say text.html but turbo still seems to work ie it just replaces the frame with new content if I submit a forming the logs it says request.format = text/vnd.turbo-stream.html

I have found now that in the controller I can use turbo_frame_request?, apparently supplied by the gem to find out f the method is from turbo

This is quite a big change and un documented or have I got things wrong?

I am not to sure how to implement this using redirect to login with devise
as I seem to need to respond with text.html and not a turbo_stream.erb partial


I am interested in knowing if you got around this. I have a similar issue.

I wanted to have a link_to that would update 2 other dom elements (not just one using the data-turbo-frame helper) so I thought following this post that adding method: :get would allow me to respond with

    respond_to do |format|

in the controller and the associated .turbo_stream.erb view would allow some turbo_stream.update to a bunch of elements but even though the turbo_link is wrapped in a turbo_frame_tag I still get text/html for the request.format.

Hence, it raises an error ActionController::UnknownFormat

edit: note that if I use a button_to to post to the controller, of course it works

I have explored this little and things seem to have changed

so an actual link_to does perform a turbo load but in the controller it responds to html

so for index, edit new and show links they all do the turbo thing but
they look for a turbo Fram in the html

with create & update in the controller you can do a respond to turbo

what you can do is see if there is a request.headers like so

logger.debug "\n\nrequest.headers['Turbo-Frame']=> #{request.headers["Turbo-Frame"]} <=\n\n"

you can also do request variants

For me I am just changing the logic of my application to suit the new way of working. So for a customer I don’t acutauall have that as a table in my database its basically a user so when I want a new customer I just have a customer controller if I want to use a new customer I just use the create action which works as normal ie it responds to turbo_stream

I guess the login is for get requests you normally are just replacing a frame on the page but for post patch & delete you often do some cleaver stuff

also what helps is a link_to is now like this

link_to ''something" path_to_a

<%= link_to ‘show’, group_group_membership_path(@group, group_membership), %>
<%= link_to delete_glyph, group_group_membership_path(@group, group_membership), data:{turbo_method: :delete, turbo_confirm: ‘Are you sure?’}%>

1 Like

Oh nice, thanks!
I will check this out and see if I can make it work.

Have a good day!