这是错误消息: ActionView::Template::Error (undefin-6ren">
gpt4 book ai didi

ruby-on-rails - 'merge' :String - Rails 3. 1 的未定义方法 "test"

转载 作者:行者123 更新时间:2023-12-03 00:39:07 24 4
gpt4 key购买 nike

我有一个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返回的用户名。

我该如何解决这个问题?

最佳答案

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 />

关于ruby-on-rails - 'merge' :String - Rails 3. 1 的未定义方法 "test",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7398928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com