I need to run a conditional inside a .js.erb
file when an ajax call is made.
I have the following:
function updateContent() {
$('.organiser__holder').html('<%= escape_javascript render("filter_links") %>');
$('.houses').html('
<% if @houses.count > 0 %>
<%= escape_javascript render(@houses) %>
<% else %>
<%= escape_javascript '<div class="message-box"><p>No houses matching those parameters</p></div>' %>
<% end %>
');
$('.paginator').replaceWith('<%= escape_javascript(render("shared/house_paginator").to_s) %>');
}
I don't think this is the correct way to accomplish this but not sure what the correct way is?
Anyone have any ideas?
<% if @houses.count > 0 %>
<% markup = render(@houses) %>
<% else %>
<% markup = '<div class="message-box"><p>No houses matching those parameters</p></div>'.html_safe %>
<% end %>
function updateContent() {
$('.organiser__holder').html('<%= escape_javascript render("filter_links") %>');
$('.houses').html('<%= escape_javascript(markup) %>');
$('.paginator').replaceWith('<%= escape_javascript(render("shared/house_paginator").to_s) %>');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.