I have defined this variable within my view
<% value_one.each do |s| %>
<% document = current_user.documents.where(skill_id: s.id ) %>
<% end %>
So I'm finding the users documents based on the skill_id (s).
But I am wondering how i can move this logic into the controller and assign it to say @documents. I am unsure on how to pass the params s.id to the controller though?
Am I thinking about this wrong, or is there a simple way to do this?
Update
Based on the answer below my controller looks like so
def index
@skills = Skill.all
@documents = current_user.documents.where(skill_id: @skills.map(&:id)).all
end
I now have 1 single query (thankfully)
Document Load (0.5ms) SELECT "documents".* FROM "documents" WHERE "documents"."user_id" = $1 AND "documents"."skill_id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70) [["user_id", 1]]