Rails 3 - rendering partial js.erb

I have a simple search form that looks something like this:

app / views / search / index.html.erb

<%= form_for @search, :as => :search, :remote => true, :url => {:action => "query"}, :html => {:id => 'search-form'} do |f| %> ... <% end % <div id="search-results"></div> 

* application / controllers / search_controller.rb *

 def index @search = SearchCriteria.new end def query @search = SearchCriteria.new(params[:search]) # otherwise, perform search... @summaries = do_search @search respond_to do |format| format.js end end 

Then I have a js.erb template: * Application / views / search / _query.js.erb *

 $('#search-results').update("<%= escape_javascript(render(@summaries)) %>"); 

However, I don’t see anything fit in the "search-results" div. Do I need some template to render "@summaries"? If so, what would it be called and where would I place it (i.e. App / views / search?) (I use jquery and rails 3)

Thanks.

+4
source share
1 answer

you should rename the template file:

 app/views/search/_query.js.erb => *app/views/search/query.js.erb 

underline is not required

+10
source

Source: https://habr.com/ru/post/1343921/


All Articles