1

Im trying to for each loop true @participants collection like below:

- ([email protected]).each do |participant|
    - @user = User.where(:id => 1).first
    # @user = User.where(:id => particpant.id).first ==> throws error: ...
    # (undefined method `id' for 1:Fixnum):
    #participants
      #block
        #image
          = show_avatar(@user.id)
          #name
            = @user.username

Confused on how to get the participant.id value for each looped object, cannot figure out how to after searched for a solution. Should I use a render collection instead or is there a way to get the participant.id for each looped participant? thx

1 Answer 1

2

You don't have to create a range, you can do the following, if participants is an array of participant objects:

- @participants.each do |participant|
  - user = User.where(:id => participant.id).first

It's even better to setup a rails relation.

class Participant
  belongs_to :user
end

This way you can simply do participant.user

I can't tell you how to setup those relations specifically because you did not give enough details. But this should get you started.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.