我有一個collection_select:未定義方法 '合併' 爲 「測試」:字符串 - 的Rails 3.1
<%= form_for(@feedback) do |f| %>
<div class="field">
<%= f.label :poster_id %><br />
<%= f.collection_select :feedback, :poster_id, @users, :id, @user.username, :prompt => "Select your username" %><br />
<%= f.number_field :poster_id %>
</div>
<% end %>
這是錯誤消息:
ActionView::Template::Error (undefined method `merge' for "test":String):
15:
16: <div class="field">
17: <%= f.label :poster_id %><br />
18: <%= f.collection_select :feedback, :poster_id, @users, :id, @user.username %><br />
19: <%= f.number_field :poster_id %>
20: </div>
21: <div class="field">
app/views/feedbacks/_form.html.erb:18:in `block in _app_views_feedbacks__form_html_erb__3181571289116259961_2154876620'
app/views/feedbacks/_form.html.erb:3:in `_app_views_feedbacks__form_html_erb__3181571289116259961_2154876620'
「測試」 是爲用戶名由@user.username
返回。
我該如何解決這個問題?
這正是我想要的。我很難理解'collection_select'的定義。感謝您幫助我。 – marcamillion
如何設置默認值。例如。說我希望它自動選擇'@ user.id'(假設它具有正確的值)。我怎麼做?我嘗試在最後添加':default => @ user.id'標誌,但那不起作用。 – marcamillion
你有沒有試過:selected => @ user.id –