Fetching a partial on click

@welearnednothing

Thanks for the pointer.
i was thinking there are two ways to do this:

  1. Use Stimulus to fetch the partial and render it in the DOM, OR
  2. Return a js.erb to the user which attaches to the DOM:

e.g.

# CustomerDetailsController.rb 
def show
   @customer = Customer.find(params[:id])
    respond_to do |format|
      format.html do
      end
      format.js do
        render layout: false
      end
    end
  end

// views/customer_details/show.js.erb
$('div.test-display').html("<%= escape_javascript(render partial: 'customer_details/show', locals: { customer: @customer } ) %>");

Was wondering if you had any thoughts/ideas on the matter: should one use stimulus (as you’ve suggsted above) or just return a js.erb to the user?