Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Rails:使用Kaminari gem的AJAX分页_Jquery_Ruby On Rails_Ajax_Pagination - Fatal编程技术网

Jquery Rails:使用Kaminari gem的AJAX分页

Jquery Rails:使用Kaminari gem的AJAX分页,jquery,ruby-on-rails,ajax,pagination,Jquery,Ruby On Rails,Ajax,Pagination,我有一个Rails应用程序,我正在尝试使用添加分页 我有一个这样的控制器动作 def index .. @hotels = Kaminari.paginate_array(@hotels).page(params[:page]).per(5) .. end My index.html.haml ... .homestay-rightside.hotel-rightside = render :partial => 'hotel_rightside',

我有一个Rails应用程序,我正在尝试使用添加分页

我有一个这样的控制器动作

def index
  ..
  @hotels = Kaminari.paginate_array(@hotels).page(params[:page]).per(5)
  ..
end
My index.html.haml

  ...
    .homestay-rightside.hotel-rightside
      = render :partial => 'hotel_rightside', :locals => {:hotels => @hotels}
  ...
我的酒店_右侧部分

  - if hotels.present?
    #hotels_listing  
      = render :partial => 'hotel_details', :locals => {:hotels => @hotels}
    #hotels_pagination
      = paginate @hotels, :remote => true
My index.js.erb

   $('#hotels_listing').html('<%= escape_javascript(render :partial => "hotel_details", :locals => {:hotels => @hotels }) %>');
   $('#hotels_pagination').html("<%= escape_javascript(paginate(@hotels, :remote => true)) %>");
$('hotels#u listing').html('hotel#u details',locals=>{:hotels=>@hotels})%>);
$(“#hotels_pagination').html(“true))%>”;
现在它发出一个HTML请求,尽管我已经添加了remote true


如何将其转换为ajax请求

我猜您在项目中使用的是自定义kaminari视图,因此请查看您的视图,并确定此
:remote=>remote
是否存在,如果不存在,则将其添加到
link_to_中,除非
helper选项

例如

= link_to_unless page.current?, page, url, {:rel => page.next? ? 'next' : page.prev? ? 'prev' : nil , :class => "page-link", :remote => remote}

希望这能帮助你:在
酒店右侧
部分,你有
酒店详细信息
部分右侧??但是为什么您只在
index.js.erb
中刷新
酒店的详细信息呢
$('#hotels_listing').html(''hotel_details',:locals=>{:hotels=>@hotels})%>')
我已经更新了js.erb,因为我在erb中错误地使用了haml语法。即使在那之后,它也不起作用。是的,你是对的,阿米特。只有在做出您建议的更改后,它才起作用。谢谢!