关于will_paginate的用法,网上有很多介绍,这里不再详细说明。
will_paginate用在查询时,一定要注意在fom_tag标签里注明:method=>"get",不然,会出现查询结果从第二页开始发生错误。
因为查询的参数会在点击第二页时丢失。
Parameters: {"type"=>"student_no", "action"=>"search", "controller"=>"students", "query"=>"2"}
[4;35;1mStudent Load (0.000000)[0m [0mSELECT * FROM students WHERE (student_no like '%2%') ORDER BY student_no LIMIT 0, 1[0m
[4;35;1mStudent Load (0.000000)[0m [0mSELECT * FROM students WHERE (student_no like '%2%') ORDER BY student_no LIMIT 0, 1[0m
Parameters: {"action"=>"search", "controller"=>"students", "page"=>"2"}
[4;35;1mStudent Load (0.000000)[0m [0mSELECT * FROM students WHERE (student_no like '%%') ORDER BY student_no LIMIT 1, 1[0m
[4;35;1mStudent Load (0.000000)[0m [0mSELECT * FROM students WHERE (student_no like '%%') ORDER BY student_no LIMIT 1, 1[0m
而加上:method=>"get"之后,
Parameters: {"type"=>"student_no", "action"=>"search", "controller"=>"students", "page"=>"1", "query"=>"2"}
[4;36;1mStudent Load (0.000000)[0m [0;1mSELECT * FROM students WHERE (student_no like '%2%') ORDER BY student_no LIMIT 0, 1[0m
[4;36;1mStudent Load (0.000000)[0m [0;1mSELECT * FROM students WHERE (student_no like '%2%') ORDER BY student_no LIMIT 0, 1[0m
Parameters: {"type"=>"student_no", "action"=>"search", "controller"=>"students", "page"=>"2", "query"=>"2"}
[4;35;1mStudent Load (0.000000)[0m [0mSELECT * FROM students WHERE (student_no like '%2%') ORDER BY student_no LIMIT 1, 1[0m
[4;35;1mStudent Load (0.000000)[0m [0mSELECT * FROM students WHERE (student_no like '%2%') ORDER BY student_no LIMIT 1, 1[0m
map.resources :students,:collection=>{:search=>:get}
本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/106212,如需转载请自行联系原作者