views:

42

answers:

1

I have two tables set up in a many-to-many relationship: Incidents and Users. When a user is logged in, and they view the /incidents page (the index), I want to display all the incidents they are associated with. Unfortunately, the following error occurs:

Could not find table 'incidents_users'

It seems rails is looking for the table 'incidents_users', when I actually created the table 'users_incidents'. 'users_incidents' simply holds the user_id and incident_id.

Am I missing something obvious? I'm relatively new to rails, so the problem could be something simple that I've overlooked.

Here is the relevant section of the incidents_controller.rb

# GET /incidents
# GET /incidents.xml
def index
  @incidents = current_user.incidents

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @incidents }
  end
end

Here is the relevant section of the index.html.erb

<% for incident in @incidents %>
  <tr>
    <td><%=h incident.other_id %></td>
    <td><%=h incident.title %></td>
    <td><%= link_to 'Show', [@customer, incident] %></td>
    <td><%= link_to 'Edit', edit_customer_incident_path(@customer, incident) %></td>
    <td><%= link_to 'Destroy', [@customer, incident], :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>

Thanks! Please let me know if more information would be helpful.

+2  A: 
John Topley
That simple, huh? Thanks! :)
Magicked
Wow, thanks for the update! I'm slowly learning how to understand the official API documentation. I really appreciate your help.
Magicked
No problem :-) Don't forget the Rails Guides too: http://guides.rubyonrails.org/
John Topley