In my application I have List objects and Problem objects, Lists are made up of Problems and problems can belong to many lists. I am using HABTM on both classes and I've created their join table like so:
class AddTableListsProblems < ActiveRecord::Migration
def up
create_table :lists_problems, :id => false do |t|
t.references :list
t.references :problem
t.timestamps
end
end
def down
drop_table :lists_problems
end
end
Now, within the show view of my list I intend to display a list of all Problems and provide a "link_to" to add this problem to the current List being shown but I can't seem to figure out how to. I'm new to RoR so the solution is probably simple though I cant seem to get around it.
This is the code i currently have.
<% @problems.each do |problem| %>
<%= render problem %>
| <%= link_to "Add to current list", <How do I access the List.problems method to add the problem and create a relation?> %>
<% end %>
Thanks in advance for your help.