开发者

How to get results from my Rails 3 controller with javascript and passed in parameters?

I'm trying to get some results from my controller based one some javascript variables but I haven't the foggiest idea on how to do this.

So far I have:

   $.ajax({
        url: '/shops?state=' + state + '&city=' + city , type: 'get', dataType: 'html',
        complete: function(request){
         $("#shop_results").html("<%= escape_javascript(render :partial => 'shop_results') %>");
        }
    });

Which according to my rails console IS hitting my controller and sending in the parameters but my controller:

  def shops
    @maps = Map.where("state LIKE ?", "#{params[:state]}")
    respond_to do |format|
      format.html
      format.js
    end
  end

my view:

  <div id="map_canvas" style="width: 980px; height: 400px"></div>

  <div id="shop_results">
    <%= render :partial =>"shop_results"%>
  </div>

and the shop_results partial has the code displaying the array:

  <ol class="shop_list" style="background:blue;">
    <% @maps.each do |m| %>
      <li><% link_to m.shop_name ,"#" %></li>
    <% end %>
  </ol>

Butttt nothing is showing开发者_高级运维 up in my view where the partial is called


Not exactly sure what you mean by "it's not returning anything in the console", but if you're doing a "like" query, wouldn't you want some % signs in there? Are you attempting to do state name completion?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜