2012-07-15 46 views
0

有一個局部視圖,通過單擊鏈接加載照片。 test_method方法需要page_id來加載它們。在加載它們之後,page_id必須遞增並鏈接「更多照片」。Rails 3.2.3和ajax - 更新當前頁面索引

#家用/ index.html.erb

<%= link_to "More photos", {:controller => "home", :action => "test_method", :page=>@current_page }, :remote => true,:id => 'lnk_more' %> 
<input type=hidden value="<%[email protected]_page%>" id='current_page' /> 

控制器

def test_method 
    @current_page = params[:page] 
    @paged_photos = get_photos(:page=>@current_pag) 
    @current_page +=1 
    respond_to() do |format| 
     format.js 
end 

#家用/ test_method.js.erb

$("#current_page").val(<%= @current_page%>); 

但是它不起作用,因爲我做錯了什麼。什麼做錯了,我該如何解決?

回答

0

你會得到什麼錯誤?還有就是在你的控制器代碼一個錯字 - 與最終

+0

你能接受我的反應,如果它回答您的問題代替

@paged_photos = get_photos(:page=>@current_pag) 

@paged_photos = get_photos(:page=>@current_page) 

和密切的respond_to? – saihgala 2012-08-23 07:32:02