gpt4 book ai didi

ruby-on-rails - collection_select,未定义的方法 `map' 为 nil :NilClass

转载 作者:行者123 更新时间:2023-12-04 06:31:03 24 4
gpt4 key购买 nike

我在 @user = User.new 中添加了行以确保它不是零。哪个对象为零?

undefined method `map' for nil:NilClass

Extracted source (around line #11):

8: <%= f.hidden_field(:width)%>
9: <%= f.hidden_field(:height)%>
10: <% @user = User.new %>
11: <%= collection_select(@user, :full_name, @user_array, :id, {:prompt => 'true'}, {:class=>'select'})%>
12: <div class="submit-button">
13: <%= submit_tag("Tag the person!")%>
14: </div>

最佳答案

@user_arraynil .确保它设置了一组用户以避免出现此错误消息。

或者,设置 @user_array[] (一个空数组)如果你不想在`select 中显示任何选项,例如:

collection_select @user, :full_name, @user_array || [], :id, 
{ prompt: 'true' }, { class: 'select' }

关于ruby-on-rails - collection_select,未定义的方法 `map' 为 nil :NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10741810/

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