0

I currently have two divs, one that contains a search bar and one that contains a partial, as such:

<div class="search_div">
    <%= form_tag(barpage_outings_path, :method => :get, :id => 'bars_search_form', :remote => true ) do %>
        <div id="user_search" class="in-field">
            <%= text_field_tag('search', '', :id => 'search_field') %>
            <%= label_tag 'search_field', 'Search For Locations' %>
            <%= submit_tag "", :id => "search_button" %> 
        </div>
    <% end %>
</div>

<div id="bar_partial">
    <%= render(:partial => "bar_results") %>
</div>

It renders a partial just fine upon page load, but I'd like it to refresh the partials contents after each search submission.

I have the form bound to an AJAX call, like such:

$('#bars_search_form').bind('ajax:success', function(){

   $('#bar_partial').html("<%= escape_javascript(render(:partial => 'bar_results')).html_safe %>");

});

The problem is, instead of refreshing the partial, it just outputs my escape javascript command as plain text. Can anyone see what I'm doing wrong (or even if I'm going about this in the completely wrong way?)

1 Answer 1

0

What about to make a new action that render your results? I think this is a better solution to your problem.

Sign up to request clarification or add additional context in comments.

2 Comments

I thought about that, too, but I wasn't sure how to get a new action to fire upon submitting search results without binding it to an AJAX call, and -- as you can see -- my JS solution isn't working too great.
You can call a javascript function that execute to ajax request with onSubmit in your form or bind it in your submit button.

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.