未定义的方法'merge'为“test”:String - Rails 3.1

时间:2011-09-13 08:32:56

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我有一个collection_select:

<%= 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'

“test”是@user.username返回的用户名。

我该如何解决?

2 个答案:

答案 0 :(得分:11)

collection_select的签名是:

def collection_select method, collection, value_method, text_method, options = {}, html_options = {}

我不确定你要做什么,也许这就是你想要的:

<%= f.collection_select :poster_id, @users, :id, :username, :prompt => "Select your username" %><br />

答案 1 :(得分:1)

我不得不考虑这样的输入,让它在我脑海中变得有意义......

collection_select'模型字段','下拉菜单中的选项集','值的模型字段','菜单中显示的模型字段'

这有助于我理解