Ask A Question

Notifications

You’re not receiving notifications from this thread.

Inline Editing with Turbo Frames in Rails Discussion

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.

Reply

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

Reply

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, ....

Reply

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 %>
Reply

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

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.