看板 Ruby 關於我們 聯絡資訊
環境:Ruby 1.8.6, RoR 1.2.5 list.rhtml 口 AAA_checkbox 口 BBB_checkbox [submit] 小弟想要在按下submit之後, 可以更新check box裡面object的某些值後回到list 下面是我的code -------------------- Model class Goal < ActiveRecord::Base has_many :tasks end class Task < ActiveRecord::Base belongs_to :goal end -------------------- view, list.rhtml <% form_tag :action => 'set_check', :goal_id => goal do %> <% for task in goal.tasks %> <%= check_box('task', :checked, {:checked => task.checked} ) %> <%= h(task.name) %> <% end %> <%= submit_tag "submit" %> <% end %> -------------------- controller, user_controler.rb def set_check @goal = Goal.find(params[:goal_id]) @tasks = @goal.tasks for task in @tasks task.update_attributes(params[:task]) #update end redirect_to :action => 'list' end -------- 我用debug去看時, 發現controller裡的for迴圈, 始終都沒跑進去, 這樣回到list時, 所有check box 都只會跟著第一個check box勾選變動 不知道這樣寫是哪邊出了問題(不好意思, 觀念都還不熟), 還請高手提示一下 -------- 還有小弟看完AWDR之後, 嘗試想做個作品, 結果沒想到上面的check box問題就搞了兩天= = 不知道是我程度太差, 還是接下來可以在看哪本, 接近實戰一點的 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.232.9.7 ※ 編輯: ilake 來自: 125.232.9.7 (11/30 23:00)
godfat:我不是很熟,所以不是很確定這樣錯在哪,但是看起來覺得 12/01 01:15
godfat:有那麼一點怪怪的,我覺得你可以把AWDR看更熟,不用找其他書 12/01 01:15
godfat:and, form_for 不好嗎?盡量不要用 ooo_tag 12/01 01:16
shelary:看起來是名稱重覆...因為你每個checkbox都同名字丫 >_< 12/01 04:43