2013-03-29 31 views
1

我有一個簡單的模型,同意:從業者約會和考勤卡(多少時間在某一天的工作路線不是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 

當我運行耙路線,我清楚地看到

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} 

,但我可以在瀏覽器中看到,對於一個約會的鼠標懸停顯示鏈接是: 本地主機:3000 /約會/ 6

和對於編輯它給 本地主機:3000 /約會/ 6 /編輯

爲什麼不能軌解決這條路呢?

回答

1

我懷疑問題是不是路由到您的預約控制器初始請求,而是在呈現顯示/編輯時,您的約會控制器/視圖正嘗試創建鏈接而不傳遞有效的約會。如果我是正確的,你的堆棧跟蹤可能會指向一個link_tourl_for,或appointment_path電話,但在具有背景下已經開始運行您的預約控制器

另一種方法來驗證這一理論將清除出你的AppointmentController.show/edit,也明確了自己的看法任何邏輯。

+0

它不轉儲任何堆/跟蹤信息...我只是得到了無益的建議,以「跑耙路線」的更多信息。 –

+0

好的。一個快速的事,試圖將刪除一切從/views/appointments/show.html.erb的,然後訪問/約會/ 1(或其他)。這個錯誤可能會產生誤導,因爲它可能意味着控制器被發現並運行,但遇到了爲視圖創建鏈接的錯誤。 –

+0

我認爲你最終是對的。在我的顯示和編輯中,我使用了以下鏈接: <%= link_to'顯示約會',約會路徑(@timecard)%> | 因爲我複製從考勤的導航選項(?類似的邏輯和關係,右)@timecard是零進來,所以我想這是無法呈現相應的HTML鏈接 - 因此,它炸燬了。 –

1

嘗試這樣做,看看是否在控制檯有什麼變化......

shallow do 
    resources :locations do 
    resources :practitioners do 
     resources :timecards 
     resources :appointments 
    end 
    end 
end 
+0

試過這個。但它給了我同樣的結果。 –

+0

但是,這可能是更好的語法,所以我會喜歡它。 –