asc99c
asc99c

Reputation: 3905

Rails - do AJAX update using HTML template

Apologies if this is asked before, but I can't find it...

I've got a page with a button bar that I need to update as the state of the page changes. The button bar is rendered with a partial.

The user can update the state with various AJAX actions on the page, and I'm doing various updates to the required elements. Mostly these are simple text strings, but the button bar is a bit more complex.

I'd have thought I should be able to do some variation on:

$('.button_bar').html( '<%= render :partial => 'buttons.html.erb' %>' );

But I'd need to somehow escape the render output for use in a string. While searching I came across render_to_string, but that just gives undefined method in my application.

Upvotes: 0

Views: 236

Answers (1)

fl00r
fl00r

Reputation: 83680

I am not sure if I understand right, but

 $('.button_bar').html( "<%= escape_javascript(render "buttons") %>" );

Upvotes: 1

Related Questions