I am trying to find a way to pull all notes that are assigned to a course but only when necessary. I have a show page which shows all of the notes for a quiz.
course show.html.erb
<%= @course.name %>
<% @quiz.notes.each do |note| %>
<%= link_to note.title, quiz_note_path(@quiz, note) %><br/>
<% end %>
The above code works find except it pulls all of the notes and not the notes that are assigned to that course. How can I tell rails to only pull the note if note and course name are equal?
update!
In the note new.html.erb I have am using collection_select
<%= f.collection_select(:course_ids, @quiz.courses, :id, :note_name, options = {:prompt => "Choose"}) %>
It seems like you don’t have relationship between
courseandquiz.A
coursehas manyquizzes, aquizhas manynotes. You should setup your relationship this way, so it won’t pull out unnecessary notes that are not related to the currentcourse.The trick here is to pull all notes inside a course by using
has_many :through.