New Discussion

Notifications

You’re not receiving notifications from this thread.

Inline Editing with Turbo Frames in Rails Discussion

5
General

How would you abstract the polymorphic path if you wanted to use the inline edit/fields partials both in forms that are namespaced like in an admin route (e.g. a form at admin/settings/show) but also a form that is not namespaced (e.g. a form at articles/show). Not sure how to abstract these polymorphic routes so that they work in both cases.

Hey Lee, did you ever figure this out? I am currently struggling with the exact same issue.

If instead of passing in the model as a lone variable, you could pass in an array like [:admin, @article], and within the partial where you render the link, you could simply pass all of that in like so link_to model, ....

Such a great tutorial. Small enhancement for the form validation errors.

In the _inline_fields.html.erb I added my render for the validation_errors (similar to other tutorials) so that the flash message is shown on an invalid save.

<% frame_id = dom_id(f.object, "#{ attribute }_turbo_frame") %>
  <%= turbo_frame_tag frame_id, class: "contents" do %>
    <%= render "validation_errors", model: f.object %>
    <div class="flex flex-row items-center mt-4">
      <%= yield %>
      <%= f.button class: "ml-2 btn-primary inline-action" do %>
        Save <%= f.object.class.human_attribute_name(attribute) %>
      <% end %>
      <%= link_to "Cancel", polymorphic_path(f.object), class: "cancel inline-action" %>
    </div>
  <% end %>

Chris why does the source code for the episode not match the video at all?

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.