2012-02-28 70 views
0

在控制器中,我有@users_shown。在視圖中,我使用@users_shown提供了部分_attendants.html.haml爲什麼渲染一個局部後,@ users_shown是否爲零?

沒關係,但在這個頁面上有一個按鈕叫做attend_again,當你點擊這個按鈕時,它將通過AJAX渲染局部_attendants.html.haml

問題是在部分_attendants.html.haml,@users_shownnil。我不知道爲什麼。

文件_attendants.html.haml喜歡這個

- unless @users_shown.blank? 
    [email protected]_shown.each do |user| 
    user.name,user.id 
+0

你可以給它更多的信息?如果可能,我希望看到ajax調用 – 2012-02-28 04:33:04

+0

$('#page_attendants')。html('<%= escape_javascript(render:partial =>「xxxx/_page_attendants」)%>'); – hlcfan 2012-02-28 04:36:30

+0

其實沒有ajax。 – 2012-02-28 04:54:15

回答

1

你需要設置@users_shown在被渲染AJAX控制器動作_attendants部分。這是一個完全獨立的請求,需要適當地設置所有相關數據。

+0

嗨,thx.this是沒有ajax _attendants,只是_attendants.html.haml – hlcfan 2012-02-28 04:23:25

+0

我意識到。呈現attendants.html.erb的控制器需要設置@users_shown,儘管您將其設置爲初始頁面呈現。如果您無法輕鬆設置,您可以將該值放入會話中,但我不建議您使用任何類型的對象。 – vansan 2012-02-28 21:07:30

0

嘗試添加本地的部分呈現,如:

<%= render :partial => "xxxx/_page_attendants", :locals => { :users_shown => @users_shown } %>