我有一个简单的模型:从业者有约会和考勤卡(一天工作了多少时间。
Practioners#show 显示从业者和相关的约会/考勤卡,以便我可以显示或编辑它们(或添加新的)。
看法:
<% if @practitioner.timecard.count > 0 %>
<p><strong>Time Card List</strong></p>
<table>
<tr>
<th>Hours</th>
<th>Date</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @practitioner.timecard.order("activity_date ASC").each do |t| %>
<tr>
<td><%= t.hours_worked %></td>
<td><%= t.activity_date %></td>
<td />
<td><%= link_to 'Edit', edit_timecard_path([t.id]) %></td>
<td><%= link_to 'Show', timecard_path([t.id]) %></td>
<% end %>
</table>
<% else %>
<p><strong>No Time Cards to display</strong></p>
<% end %>
<%= link_to "[Add Time Card]", new_practitioner_timecard_path(@practitioner) %>
<% if @practitioner.appointment.count > 0 %>
<p><strong>Appointment List</strong></p>
<table>
<tr>
<th>Name</th>
<th>Date</th>
<th>Duration</th>
<th>New?</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @practitioner.appointment.order("appointment_date ASC").each do |r| %>
<tr>
<td><%= r.patient.name %></td>
<td><%= r.appointment_date %></td>
<td><%= r.duration %> </td>
<td><%= r.first_time %></td>
<td />
<td><%= link_to 'Edit', edit_appointment_path(r.id) %></td>
<td><%= link_to 'Show', appointment_path(r.id) %></td>
<% end %>
</table>
<% else %>
<p><strong>No Appointments to display</strong></p>
<% end %>
路线:
get "welcome/index"
get "admin/index"
resources :patients
resources :locations, :shallow => true do
resources :practitioners, :shallow => true do
resources :timecards, :shallow => true
resources :appointments, :shallow => true
end
end
当我运行 rake 路线时,我清楚地看到
edit_appointment GET /appointments/:id/edit(.:format) appointments#edit
appointment GET /appointments/:id(.:format) appointments#show
当我单击时间卡的编辑或显示时,它工作正常。当我单击约会的编辑或显示时,它会出错:
No route matches {:action=>"edit", :controller=>"appointments", :id=>nil}
但我可以在我的浏览器中看到约会显示链接的鼠标悬停是:localhost:3000/appointments/6
对于编辑它给出 localhost:3000/appointments/6/edit
为什么rails不能解决这条路线?