Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法';合并';至于;测试“:字符串-Rails 3.1_Ruby On Rails_Ruby On Rails 3_Ruby On Rails 3.1 - Fatal编程技术网

Ruby on rails 未定义的方法';合并';至于;测试“:字符串-Rails 3.1

Ruby on rails 未定义的方法';合并';至于;测试“:字符串-Rails 3.1,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,我有一个集合\u选择: <%= 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

我有一个集合\u选择:

<%= 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'
ActionView::Template::Error(未定义“test”的“merge”方法:String):
15:     
16:   
17:
18:
19: 20: 21: 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\u-views\u-feedbacks\u-form\u-html\u-erb\u 3181571289116259961\u 2154876620'
“test”是由
@user.username
返回的用户名


如何解决此问题?

所选集合的签名为:

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 />
“选择您的用户名”%>

我必须以这种方式思考输入,才能让它在我的头脑中有意义

集合\选择“模型字段”、“下拉菜单中的选项集合”、“值的模型字段”、“要在菜单中显示的模型字段”


这让我明白了这正是我想要的。我很难理解
collection\u select
的定义。谢谢你的帮助。我如何设置默认值。例如,假设我希望它自动选择
@user.id
(假设该值正确)。我该怎么做?我尝试在末尾添加
:default=>@user.id
标志,但没有成功。