Back

config/routes.rb中,root路径要放在下面,否则会引起分页链接错误 (root path with karminari)

发布时间: 2014-05-10 02:49:00

今天很奇怪,遇到一个问题: kaminari 在分页时 ,如果 被分页内容是 root_path, 那么在分页helper中的路径, 就不是完整的。形式(例如 /client/pids?page=2 ) ,而是以 '/?page=2' 这样的形式显示。 ( today I met a problem caused by a root_path declaration in the top of my routes.rb file .  the problem is : the links in pagination helper is not displayed as standard path, but a root path) 

解决办法: 把 config/routes.rb中的 root声明放在 下面 ( the solution is: simply put the 'root' declaration to the bottom of the page) 

# in config/routes.rb  
-  root :to => 'client/pids#index'
+  #root :to => 'client/pids#index'
   match '/logout' => "users#logout", :as => :logout
   namespace "client" do
     resources "vendors", "pids", "os", "pid_logs",
     ......
     end
   end
 
+  root :to => 'users#index'

Back