Rails ajax 分页与部分
我正在使用 will pagaginate gem 进行分页。事情对我来说很好。我正在尝试 ajaxify 它,并且遵循 http ://railscasts.com/episodes/240-search-sort-paginate-with-ajax 教程。但 Ajax 请求并没有被我解雇。
我有一个索引视图。该视图呈现一个名为“_browser_form”的部分,而该部分又呈现一个名为“_listing”的部分。所以我想对 _listing 中的表进行分页。 如果我的方法有任何错误,请告诉我。
我的控制器:
def index
@ics = Ic.search(params[:root_name],params[:suite_name],params[:case_name],params[:name],'f').paginate(:per_page =>5, :page => params[:all_ics])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @ics }
end
end
我的_browser_form.html.haml,它是从index.html.haml渲染的
- form_tag "/ics/mass_action", :method => :post, :multipart => true do
<div id="update_ics_table">
= render "listing", :show_check_boxes => show_check_boxes, :root_name=>params[:root_name],:suite_name=>params[:suite_name],:case_name=>params[:case_name],:name=>params[:name],:ic_filter=>1
</div>
=will_paginate @ics,:param_name=>:all_ics
我的index.js.erb文件:
$('#update_ics_table').html("<%= escape_javascript(render :partial => 'listing' ,:object => @ics) %>")
我的.js文件:
$(function () {
$('#update_ics_table .pagination a').live('click',
function () {
$.getScript(this.href);
return false;
}
);
});
谢谢, 拉姆亚。
I am using the will paginate gem for pagination. Things wok fine for me.I am trying to ajaxify it and I followed the http://railscasts.com/episodes/240-search-sort-paginate-with-ajax tutorial. But Ajax request is not being fired for me.
I have a index view. The view renders a partial called "_browser_form" which in turn renders a partial called "_listing". So I wanted to paginate the table in the _listing.
Please let me know if there is any error in my approach.
My controller:
def index
@ics = Ic.search(params[:root_name],params[:suite_name],params[:case_name],params[:name],'f').paginate(:per_page =>5, :page => params[:all_ics])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @ics }
end
end
My _browser_form.html.haml which is rendered from index.html.haml
- form_tag "/ics/mass_action", :method => :post, :multipart => true do
<div id="update_ics_table">
= render "listing", :show_check_boxes => show_check_boxes, :root_name=>params[:root_name],:suite_name=>params[:suite_name],:case_name=>params[:case_name],:name=>params[:name],:ic_filter=>1
</div>
=will_paginate @ics,:param_name=>:all_ics
My index.js.erb file:
$('#update_ics_table').html("<%= escape_javascript(render :partial => 'listing' ,:object => @ics) %>")
My .js file:
$(function () {
$('#update_ics_table .pagination a').live('click',
function () {
$.getScript(this.href);
return false;
}
);
});
Thanks,
Ramya.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除您在 Javascript 中执行的操作并在控制器中执行此操作:
类似: 让 will_paginate 与 Ajax 配合使用的最佳方式
Remove what you're doing in the Javascript and do this in the controller:
Similar: Best way to get will_paginate working with Ajax
这可能与您使用 HAML 视图和 js.erb 文件有关,但我不使用 HAML,所以我不能确定。看看nex3的答案:如何发回js。 Rails 中的 haml
如果情况并非如此,我认为您需要将您的 respond_to 控制器操作块更改为:
It might have something to do with the fact that you're using HAML views and an js.erb file, but I don't use HAML so I can't be certain. Have a look at nex3's answer at this SO: How to send back js.haml in rails
If that is not the case, I think you need to change your respond_to controller action block to this: