加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – “test”的未定义方法“merge”:String – Ra

发布时间:2020-12-17 04:04:20 所属栏目:百科 来源:网络整理
导读:我有一个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
我有一个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,@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返回的用户名.

我该如何解决这个问题?

解决方法

collection_select的签名是:

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读