1

I am using rails 4 and making an application in which Question_sets has many Questions and Questions has many answers. Now what i want is to update one attribute of question model and one attribute of answer model through questions sets.

       @question_set.questions.inspect

It gives the output

OUTPUT:

ActiveRecord::Associations::CollectionProxy 

[Question id: nil, title: "werewr", question_type: "Slider", description: "ewrewrew", is_shown_in_report: false, question_set_id: nil, user_id: nil, created_at: nil, updated_at: nil]

But when i am accessing any of the attribute or trying to update it, it will give an error that is undefined "attribute_name".

can any tell how to access the attributes of the this collectionproxy object.

1 Answer 1

3

questions is returning a collection (like an Array) of Question objects. So you need to itterate over the collection:

@question_set.questions.each do |question|
  question.title
end
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.