다 대다 관계로 두 개의 테이블을 설정했습니다. 인시던트와 사용자. 사용자가 로그인하여/사고 페이지 (색인)를 볼 때 관련된 모든 인시던트를 표시하려고합니다. 불행하게도, 다음과 같은 오류가 발생합니다레일 : 다 대다 관계에서 '테이블을 찾을 수 없습니다.'
Could not find table 'incidents_users'
내가 실제로 테이블 'users_incidents'를 만들었을 때, 'incidents_users'테이블을 찾고 레일을 보인다. 'users_incidents'는 단순히 user_id 및 incident_id를 보유합니다.
나는 분명한 뭔가를 놓치고 있습니까? 나는 레일에 비교적 익숙하지 않아, 간과 한 문제가 될 수 있습니다.
다음은 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
의 관련 섹션은 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 %>
감사의 관련 섹션입니다! 더 많은 정보가 도움이 될 경우 알려 주시기 바랍니다.
간단합니다. 감사! :) – Magicked
와우, 업데이트 주셔서 감사합니다! 나는 공식적인 API 문서를 이해하는 방법을 천천히 배우고있다. 도와 주셔서 정말 고맙습니다. – Magicked
문제 없음 :-) Rails 가이드도 잊지 마십시오. http://guides.rubyonrails.org/ –