Sending info to rails server without a render response

I have a dropdown menu with checkboxes that reflects settings made by the user. I want to save these settings in the current session.

First I tried a <%= link_to … method: :put %>

I always got a GET request nevertheless although the generated html included <a href ... data-method="put" ... </a>. Do I need to create a form submission instead?

Just to test things I routed the request to a GET in config/routes.rb, but then I ran into the 2nd problem, that I was unable to send back “got it, thx, just keep going” to the browser. I saw “render :nothing => true” on the internet, but it didn’t work either, rails still said " Template is missing". To everything I tried rails complained that I need to render something in return.

I found people talking about AJAX to accomplish it, but now rails 7 uses the new turbo.

How do I accomplish this or what doc/guide do I need to read to progress? Thanks!

Try making that a button_to with a turbo_method. You can also use a link_to with a turbo_method, but button is more semantic, since it will get an actual form built around it, and not rely on JavaScript to do that at the last moment. One reason to prefer link_to and turbo_method would be if that element was being added inside another form. You can’t nest forms.

Walter

1 Like

Works like a charm. Thanks Walter, super helpful! I’ll read a bit about the new turbo framework and try to understand it better.