作者poopoo888888 (阿川)
看板Ruby
標題Re: [問題] 關於form_for
時間Fri Nov 26 16:11:48 2010
我自己找到問題了
map.resources :assess有錯
應該要打複數
map.resources :assesses
但又有個問題想問
就是為什麼這裡要打複數?
我創model時是單數 呼叫這個model時也是以單數型態
只有在schema內它是顯示複數型態
想問單數/複數的規則是什麼
謝謝!
※ 引述《poopoo888888 (阿川)》之銘言:
: 環境:
: e.g. Ruby 1.8.7 Rails 2.2.2
: controller內打了
: @assess = Assess.find_by_id(params[:id])
: 在相對應的view輸入了
: <%= @assess.status %>
: <%= @assess.f_id %>
: 結果在瀏覽器中 這兩個attributes都正確顯示 沒問題
: 接著我在view增加了
: <% form_for(@assess) do |f| %>
: <%= f.submit "Enter" %>
: <% end %>
: 我想逐步測試form_for的功能 先試著做個送出鈕
: 然後在config\routes.rb輸入了
: map.resources :assess
: 結果瀏覽器卻顯示錯誤
: NoMethodError in Faculty#evaluate
: Showing app/views/faculty/evaluate.erb where line #28 raised:
: You have a nil object when you didn't expect it!
: The error occurred while evaluating nil.to_sym
: Extracted source (around line #28):
: 26: <%= @assess.status %>
: 27: <%= @assess.f_id %>
: 28: <% form_for(@assess) do |f| %>
: 29: <%= f.submit "Enter" %>
: 30: <% end %>
: 請問我漏打了什麼呢?
: 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.166.198.192
1F:→ godfat:我覺得最重要的理由只是他開心.. XD 11/26 16:47
2F:推 Jcrt:routes.rb對應的是controller不是model喔~ 11/26 21:08
3F:→ poopoo888888:J大 我有點不懂 因為是controller所以為複數..? 11/26 22:57
4F:→ hellolucky:你建立一個單數的controller試看看吧 11/26 23:24