mercredi 7 septembre 2016

undefined method `map' for :id:Symbol

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>

How can I solve this error so that only the challenges for that respective user are listed?

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

duels/_user_challenges.html.erb

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

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

Aucun commentaire:

Enregistrer un commentaire