ajax请求无法在rails

时间:2016-07-28 06:15:19

标签: ruby-on-rails ajax

我有一个带有此代码的控制器

  def index
    if params["destination"].present?
      @destination = params["destination"]
      @destination_name = params["destination_name"]
      @new_loc = (params["current_destination"].present? && (params["destination"] != params["current_destination"]))
......
......
          if (@new_loc == false) && params["city_areas"].present?
            city_area_ids = params["city_areas"].map(&:to_i)
            @hotels = @hotels.select{|ht| city_area_ids.include?( @booking_hotel_partner_details.select{|f| f.partner_booking_hotel_id==ht['id'].to_i}.first.booking_hotel.hotel_city_area_id ) }
          end   
end

hotels.index.html.haml

$('.checkbox-custom').on('change',function(){
    filter_home_stays();
    $('#searchForm').trigger('submit.rails');
});

hotels.index.js.erb

if (new_loc == "true") {
  $('#city-areas').children('ul.open-dropdown').remove();
  $('#city-areas').append('<%= escape_javascript(render :partial => 'filter', :locals => ({:city_areas => @city_areas})) %>');
  $('#city_areas .local-amenities-drpdown').mCustomScrollbar({
    theme:"rounded-dark",
    mouseWheelPixels: 500,
  });
}

首次单击复选框时,过滤器正常工作。 但是在我改变目的地之后它不起作用 有人能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

这就是我所做的。

if (new_loc == "true") {
  $('#city-areas').children('ul.open-dropdown').remove();
  $('#city-areas').append('<%= escape_javascript(render :partial => 'filter', :locals => ({:city_areas => @city_areas})) %>');
  $('#city_areas .local-amenities-drpdown').mCustomScrollbar({
    theme:"rounded-dark",
    mouseWheelPixels: 500,
  });
  $('.city_area.checkbox-custom').on('change',function(){
    filter_home_stays();
    $('#searchForm').trigger('submit.rails');
  });   
}

谢谢你们大声喊叫。你们摇滚吧!