さて、私は教授と学生がログオンして予定を作成/編集するための予定サイトを作成しています。私は教授側をやらせていますが、学生たちと苦労しています。現在、学生が教授との予定から自分自身を削除するために、予定の横にあるボタンをクリックするようにしようとしています。これで、アポイントメント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
見る:
<% @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 %>
ご覧になりたい場合は、ここに私のファイルにリンクを含めました。 マイファイルを表示するには、ここをクリックしてください。 また、すべてが予定コントローラーで行われます。この問題は、学生の表示ビュー(削除ボタンを押す場所)にあります。
解決策:わかりました。皆さんの助けを借りて、機能しました。@appointment = Appointment.find_by_id_and_student_id(params [:id]、session [:student] .user_id)@ appointment.update_attribute(:student_id、nil)