Rails 3-渲染部分js.erb [英] 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 *
*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
然后我有了一个js.erb模板: * app/views/search/_query.js.erb *
I then have a js.erb template: *app/views/search/_query.js.erb*
$('#search-results').update("<%= escape_javascript(render(@summaries)) %>");
但是,我看不到搜索结果" div中有任何内容.我是否需要某种模板才能呈现"@summaries"?如果是这样,它的名称是什么,我该在哪里放置它(即app/views/search?)(我正在使用jquery和rails 3)
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)
谢谢.
推荐答案
您应该重命名模板文件:
you should rename your template file:
app/views/search/_query.js.erb => *app/views/search/query.js.erb
下划线是不必要的
这篇关于Rails 3-渲染部分js.erb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!