Turbo Frame Redirect and Render

@clap Alexandru Clapou
Mon, 13 Oct 2025 16:42:01 +0000

Hi, I am trying to learn turbo and I’m working at the following thing:

Have a modal to create a resource. Here I want to either re-render the view if the form validation fails, or redirect to edit_path if the resource is saved.

index.html




        todo sort

      <%= link_to 'New Store', new_admin_store_path, data: {turbo_frame: 'new_store'}, class:'action-button' %>


    <%= render partial: 'stores', locals: {stores: @stores}%>
    <%= turbo_frame_tag 'new_store' %>


new.html.erb

<%= render "shared/popup", frame_id: "new_store", classes:'size-full' do %>
  <%= render partial: 'form' %>
<% end %>

_popup.html.erb

<% classes ||= ''%>
<%= turbo_frame_tag frame_id do %>
  <% if turbo_frame_request? %>


        <%= inline_svg_tag 'icons/close.svg',
          class: 'highlight-hover',
          data: { action: 'click->popup#close' } %>
        <%= yield %>


  <% else %>
    <div class="<%=classes%>">
      <%= yield %>

  <% end %>
<% end %>

_form.html.erb

  <%= @store.errors.messages %>
  <%= form_with model: [:admin, @store] do |form| %>



          <%= form.label :name, 'Name' %>
          <%= form.text_field :name, class: "w-full form-input" %>


          <%= form.label :slug, 'Slug' %>
          <%= form.text_field :slug, class: "w-full form-input" %>




          <%= form.label :description, 'Description' %>
          <%= form.textarea :description, rows: 3, class: "w-full form-input" %>



    <%= form.submit class: 'action-button mt-2' %>
  <% end %>

Stores#create

    def create
      @store = Store.new(store_params)
      if @store.save
        redirect_to edit_admin_store_path(@store, format: :html)
      else
        render :new
      end
    end

I tried to add data: {turbo_frame: ‘_top’} inside the form_with, but this does not allow me to re-render the new view.

I wonder how should i solve this issue, any help is appreciated. Thank you!