好吧,我正在爲教授和學生創建一個約會網站來登錄和創建/編輯約會。我已經完成了教授方面的工作,但我正在與學生們奮鬥。現在我正在努力讓學生點擊他們預約旁邊的按鈕,從他們與教授之間的約會中解脫出來。現在我可以輕鬆地刪除約會ID,約會將會消失,但是我想從約會中刪除student_id,以便其他學生稍後可以選擇該約會。這裏是我的代碼: 控制器:你沒有想到它會有一個零對象(約會頁面)
def destroy
if session[:professor] != nil
@appointment = Appointment.find(params[:id])
@appointment.destroy
end
if session[:student] != nil
@appointment = Appointment.find_by_id_and_student_id(params[:id],params[:student_id])
@appointment.destroy(params[:student_id])
end
end
VIEW:
<% @appointments.each do |appointment| %>
<tr>
<td><%= appointment.professor_id %></td>
<td><%= appointment.student_id %></td>
<td><%= appointment.timeslot %></td>
<td><%= link_to 'remove appointment', appointment, confirm: 'Are you sure?', method:
:delete %></td>
</tr>
<% end %>
,如果你想看看我在這裏跟我的文件包含的鏈接。 CLICK HERE TO VIEW MY FILES. 此外,一切都發生在約會控制器。並且這個問題出現在顯示學生視圖中(你按下刪除按鈕)。
SOLUTION: 好吧,所以我得到它的工作,由於我從你們的幫助。因此,這裏是我做過什麼: @appointment = Appointment.find_by_id_and_student_id(PARAMS [:編號],會話[:學生] .user_id) @ appointment.update_attribute(:student_id數據,無)
哪些行發生錯誤? – 2012-03-06 15:57:05
app/controllers/appointmentments_controller.rb:118:在'destroy' – user1179269 2012-03-06 16:00:38
這並不能幫助您知道您提供的代碼中的哪一行,因爲它沒有任何對行號的引用。在指出該行的代碼中添加註釋。 – 2012-03-06 16:01:47