我是RoR和AJAX,jquery等的新手。我试图在视图中进行Ajax调用,但没有发生。
对应的控制器(product_search_controller,rb)为:
def index
@products = querySolr(params[:q])
@productsProxy = Array.new
if @products != nil
@products.each do |p|
@productsProxy.push(ProductProxy.new(p))
end
else
@productProxy = []
end
@taxons = @productsProxy.map(&:get_taxonomy).compact.uniq
respond_with("Search Results") do |format|
format.js
format.html
format.xml { render :xml => @productsProxy, :only => [:name, :permalink, :description, :mrp], :methods => [:designer, :taxons, :price] }
end
end
对应的视图(views / product_search / index.hrml.erb)为:
'products', :locals => {:products => @productsProxy, :taxons => @taxons, :scope => self, :scope_type => "Search"} %>
'shared/inf_scroll', :locals => {:url => "?&page=", :total_count => @total_count} %>
/views/product_search/_products.html.erb:
h(params[:keywords])) %>
'product_listing_feature', :locals => {:scope => scope, :scope_type => scope_type} %>
'product_listing', :locals=>{:collection=> taxonProducts} %>