Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - render partial js.erb

I have a simple search form that looks something like:

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>

*app/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

I then have a js.erb template: *app/views/search/_query.js.erb*

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

However, I don't see anything being put into the 'search-results' div. Do I need some sort of template in order to render "@summaries"? If so, what would it be named and where would I place it (i.e. app/views/search?) (i am using jquery and rails 3)

Thanks.

like image 320
codecraig Avatar asked Dec 27 '22 23:12

codecraig


1 Answers

you should rename your template file:

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

underscore is unnecessary

like image 159
fl00r Avatar answered Jan 04 '23 18:01

fl00r