0

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.

1 Answer 1

1

I am not sure if I understand right, but

 $('.button_bar').html( "<%= escape_javascript(render "buttons") %>" );
Sign up to request clarification or add additional context in comments.

2 Comments

Yep! Absolutely spot on - fantastic.
A shortcut helper you might be interested, <%= j render "buttons" %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.