我通過哈希迭代並將值顯示爲單選按鈕。哈希是這樣的:訪問控制器中的發佈數據
{
1=>["a", "b"],
2=>["c"],
3=>["a", "d", "f", "g"],
4=>["q"] ..
}
選擇值後,參數變成:
{ "commit"=>"vote", "authenticity_token"=>"db863239855c9f73b9ae54c37f6b92c858acb56f", "1"=>"a", "2"=>"c", "3"=>"d", "4"=>"q"}
如何訪問,以更新控制器的更新方法,這些值(POST數據)計數字段?我嘗試過這樣。
@votings = Voting.find(:all, :conditions => {params[:k]=>params[:val]})
@votings.each do |voting|
voting.update_attribute('vote_count',
voting.vote_count+1)
end
但給出了這樣的錯誤:
You have a nil object when you didn't expect it! The error occurred while evaluating nil.each..
誰能告訴我哪裏錯了?
爲什麼你堅持社區wiki的客觀問題?讓這些人獲得他們應得的聲望。 – erik 2009-08-06 14:23:33