這裏是我的代碼段工程完全按照預期:Rails的collection_select沒有工作,但相當於選擇與options_from_collection_for_select確實
<%= f.select(:other_model_id,
options_from_collection_for_select(
OtherModel.all,
:id,
:full_name,
{ :selected => @this_model.other_model_id})) %>
但由於某些原因,這不起作用:
<%= f.collection_select :this_model, :other_model_id,
OtherModel.all, :id, :full_name %>
有我得到的錯誤是:
未定義的方法`merge'爲:full_name:符號
有什麼建議嗎?事實:full_name與工作代碼正常工作,導致我相信我搞砸了簡化的collection_select代碼中的語法,並且問題不在其他地方。
嘗試爲參數添加'()'。否則嘗試添加最後一個參數爲「{}」。 – Zabba