gpt4 book ai didi

ruby-on-rails - :id:Symbol的未定义方法 'map'

转载 作者:行者123 更新时间:2023-12-03 08:26:40 25 4
gpt4 key购买 nike

ActionView::Template::Error (undefined method `map' for :id:Symbol):
# duels/_user_challenges.html.erb
1: <div id="dropdown-no-2">
2: <%= collection_select 'challenge_id', challenges, :id, :full_challenge, include_blank: true %>.
3: </div>

当用户选择一个用户使用 duel时,则仅应显示该用户的质询。

决斗/_dueler_fields.html.erb
<%= f.collection_select :user_id, User.order(:name),:id, :full_name, include_blank: true, id: "id_of_the_user_id_select_box" %>
will

<%= render :partial => 'user_challenges', locals: {challenges: Challenge.order(:deadline)} %>

<script>
$( "#id_of_the_user_id_select_box" ).change(function() {
$.ajax({
type: "GET",
url: '<%= user_challenges_path %>',
data: {name: $('#id_of_the_user_id_select_box').prop('value')}
});
});
</script>

对决/user_challenges.js.erb
$("#dropdown-no-2").html('<%=j render :partial => "user_challenges", locals: {challenges: @challenges} %>'); 

duels_controller.rb
def user_challenges
@user = User.find(params[:id])
@challenges = @user.challenges.order(:deadline)
end

最佳答案

参见http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-select

我建议使用select FormHelper实现此目的:

所以这

<%= f.collection_select :user_id, User.order(:name),:id, :full_name, include_blank: true, id: "id_of_the_user_id_select_box" %>

变成这个
<%= f.select :user_id, User.order(:name).map { |user| [user.full_name, user.id] }, include_blank: true, id: "id_of_the_user_id_select_box" %>

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

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