2010-03-23 67 views

回答

2

當您調用變量時,可以將變量傳遞到局部的實例範圍中,然後可以根據這些實例變量的值執行操作。

所以,如果你有在包含局部視圖中的局部變量item_counter,致使部分是這樣的:

<%= render :partial => "my_partial", :locals => { :item_counter => item_counter} %> 

裏面的部分,你現在可以訪問本地變量item_counter。因此在部分你可以有:

if item_counter > 0 && item_counter % 6 == 0 
    # Do exciting base 6 activity 
end 
+0

我這樣做:''my_class'if(contributor_counter)%6 == 0)&& contributor_counter!= 0' – 2010-03-23 23:02:04