gpt4 book ai didi

javascript - :id:Symbol 的未定义方法 `map'

转载 作者:行者123 更新时间:2023-12-03 06:09:59 25 4
gpt4 key购买 nike

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

如何解决此错误,以便仅列出相应用户的挑战?

决斗/_dueler_fields.html.erb

<%= f.select :user_id, User.order(:name).map { |user| [user.full_name, user.id] }, include_blank: true, id: "change-challenge-options" %>

will

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

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

决斗/_user_challenges.html.erb

<div id="dropdown-no-2">
<%= collection_select(':challenge_id', challenges, :id, :full_challenge, include_blank: true) %>.
</div>

决斗/user_challenges.html.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(:created_at)
end

def new
@duel = Duel.new
@duel.duelers << Dueler.new(user_id: current_user.id, user_name: current_user.name, user_last_name: current_user.last_name)
respond_with(@duel)
end

routes.rb

get 'duels/user_challenges', :to => 'duels#user_challenges', as: 'user_challenges'

最佳答案

将其更改为:

<%= collection_select(:duel, :challenge_id, challenges, :id, :full_challenge, include_blank: true) %>

引用collection_select

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

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