Rails form_tag remote example -


i have incredible simple form:

<%= form_tag("/portal/search", method: 'get', remote: true ) %>    <%= label_tag(:query, 'search for:') %>   <%= text_field_tag(:query) %>   <%= submit_tag("find") %>  <% end %> <div id="results"></div>  

i know documentation, can use ajax through remote option:

<%= form_tag("/portal/search", method: 'get', remote: true ) %> 

then stuck. know how generate results in view/partial, how partial inside div element? know bit of jquery, can select element. found lot of results, seem miss lightbulb moment me. using rails 4.1.6

my results simple records model, book (title, author)

thank helping!

edit

i've won cup missing point long shot. had add search.js.erb inside view folder instead of assets.

let's @results out of search method.

in controller, search method:

respond_to |format|   format.html {render or redirect_to wherever need it}   format.js  end 

then need file named search.js.erb run required js @ end of request. might like:

$('#results_div').html("<%= j @results.pluck(:title).join('<br/>') %>") 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -