2013-05-04 101 views
1

3天前我問了這個問題,但沒有回答。 以下是其他信息的鏈接:how to get paginate to work instead of getting redirected to 'public/index.html'?如何讓paginate與public/index.html一起工作? (ruby on rails 3)

我會在這裏澄清/簡化問題。

我使用public/index.html作爲我的訪問者主頁。用戶登錄後,新主頁位於'/ home'。在這個'/家',有一個飼料。我使用此視圖在我的視圖<%= will_paginate @posts %>中對分頁進行分頁。

您可能想象的問題是,當我嘗試點擊頁面上的第二頁時,鏈接爲http://www.mydomain.com/?page=2。這將重定向回public/index.html。我怎樣才能讓分頁工作正常?

在此先感謝

回答

1

爲什麼不刪除public/index.html.erb?這是一個靜態頁面,你不能像分頁一樣擁有動態元素。

爲應用程序的根請求應當由一根路由處理:

root :to => "home#index" 

然後在app/views/home/index.html.erb分頁邏輯。

+0

'public/index.html'用於匿名訪問者。我有'static_pages/home.html.erb'這是登錄用戶。我試圖讓分頁工作爲'home.html.erb' ...我如何刪除'public/index.html'並使其正確工作? – syk 2013-05-04 04:52:55