Brad Ballard


70 Experience
0 Lessons Completed
0 Questions Solved


Posted in Pagination with Stimulus

No, never did. I ended up sticking with UJS as well.

Posted in Pagination with Stimulus

I'm trying to migrate to Stimulus and I thought a good place to start would be to move all my UJS style partials that are using jQuery to Stimulus. It would be great to use one Stimulus controller for all the remote data partial rendering I do using link_to.

Thanks to a previous post, I've been successful with building a Stimulus controller and rendering a partial with using a data target. What I can't figure out is how to get my pagy pagination partial or nav to render with the link_to rendered partial.


<div data-controller="renderer">
  <%= link_to visits_physician_path(@physician), data: { remote: true, action: 'ajax:success->renderer#render' } do %>
  <% end %>
  <div data-renderer-target="display"></div>

  <div id="js-physician-pagination" class="pagination-button">
   // Where I need to render the pagination nav. 
   // Either using render nav or <%== pagy_bootstrap_nav(@pagy) %>


  def visits

    @pagy, @visits = pagy(Visit.where(physician:
                               .order(check_in: :desc)
                               .includes(:office, :user),
                          items: 5, , link_extra: 'data-remote="true"')

    respond_to do |format|
      format.html { render(partial: 'physicians/show/visit', collection: @visits) }


stimulus controller

import {Controller} from 'stimulus'

export default class extends Controller {
    static targets = ['display']

    render(evt) {
        this.displayTarget.innerHTML = evt.detail[0].body.innerHTML

visits.js.erb (what was previously being used)

$("#js-physician-container").html("<%= j render(partial: 'physicians/show/visit', collection: @visits) %>");
$("#js-physician-pagination").html("<%== j(pagy_bootstrap_nav(@pagy)) %>");

Any help on this would be great.


What would be the solution for the drag_controler.js code to make it serialized like it was with the jQuery sortable episode?
The route would need to be updated to collect and the move action would need to use each_with_index. Just can't figure out how to serialize it correctly from the drag_controller.js

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.