I want to have an AJAX call to a `destroy` action in my application, and am following example #3 of the guide [Ajax in Rails 3.1 - A Roadmap](http://madebydna.com/all/code/2011/12/05/ajax-in-rails-3.html#) to do this. I'm using Rails 3.2.8. 

i got the AJAX request working just fine, and the `destroy` action is called just as I expect it to. 
When a user requests the HTML page of the `destroy` action, I want to delete the item, and then redirect her to another page. 

The problem is that both the HTML and AJAX requests stop working when I insert code to redirect. When the code is there, an AJAX request returns 500 Internal Server Error, and an HTML request returns "The action 'show' could not be found for SafetyTestsController". When the two lines are not there, AJAX works fine and HTML still returns the same error.

**View (Unrendered):**

```
<%= link_to 'Delete', {controller: 'safety_tests', action: 'destroy', id: safety_test.id}, remote: true, method: :delete, confirm: 'Are you sure?', id: "delete_safety_test" %>

```

**View (Rendered):**

```
<a href="/safety_tests/14" data-confirm="Are you sure?" data-method="delete" data-remote="true" id="delete_safety_test" rel="nofollow">Delete</a>

```

**app/controllers/safety\_tests\_controller.rb**

```
class SafetyTestsController < ApplicationController
  respond_to :html, :js
  ...
  def destroy
    test = SafetyTest.find(params[:id])
    student_id = test.student_id
    test.destroy

    respond_with(test) do |format|
      format.js { render nothing: true }
    end

    #Two lines below should run for an HTML request but not a Javascript request.
    #When uncommented, AJAX request returns 500 Internal Server Error 
    #flash[:notice] = 'Safety test deleted successfully.'
    #redirect_to controller: 'students', action: 'show', id: student_id
  end

```

**rake routes**

```
new_user_session GET    /users/sign_in(.:format)                     devise/sessions#new
                user_session POST   /users/sign_in(.:format)                     devise/sessions#create
        destroy_user_session DELETE /users/sign_out(.:format)                    devise/sessions#destroy
                        root        /                                            dashboard#home
                    students GET    /students(.:format)                          students#index
                             POST   /students(.:format)                          students#create
                 new_student GET    /students/new(.:format)                      students#new
                edit_student GET    /students/:id/edit(.:format)                 students#edit
                     student GET    /students/:id(.:format)                      students#show
                             PUT    /students/:id(.:format)                      students#update
                             DELETE /students/:id(.:format)                      students#destroy
                       trips GET    /trips(.:format)                             trips#index
                             POST   /trips(.:format)                             trips#create
                    new_trip GET    /trips/new(.:format)                         trips#new
                   edit_trip GET    /trips/:id/edit(.:format)                    trips#edit
                        trip GET    /trips/:id(.:format)                         trips#show
                             PUT    /trips/:id(.:format)                         trips#update
                             DELETE /trips/:id(.:format)                         trips#destroy
                safety_tests GET    /safety_tests(.:format)                      safety_tests#index
                             POST   /safety_tests(.:format)                      safety_tests#create
             new_safety_test GET    /safety_tests/new(.:format)                  safety_tests#new
            edit_safety_test GET    /safety_tests/:id/edit(.:format)             safety_tests#edit
                 safety_test GET    /safety_tests/:id(.:format)                  safety_tests#show
                             PUT    /safety_tests/:id(.:format)                  safety_tests#update
                             DELETE /safety_tests/:id(.:format)                  safety_tests#destroy
               medical_forms GET    /medical_forms(.:format)                     medical_forms#index
                             POST   /medical_forms(.:format)                     medical_forms#create
            new_medical_form GET    /medical_forms/new(.:format)                 medical_forms#new
           edit_medical_form GET    /medical_forms/:id/edit(.:format)            medical_forms#edit
                medical_form GET    /medical_forms/:id(.:format)                 medical_forms#show
                             PUT    /medical_forms/:id(.:format)                 medical_forms#update
                             DELETE /medical_forms/:id(.:format)                 medical_forms#destroy
     parent_permission_forms GET    /parent_permission_forms(.:format)           parent_permission_forms#index
                             POST   /parent_permission_forms(.:format)           parent_permission_forms#create
  new_parent_permission_form GET    /parent_permission_forms/new(.:format)       parent_permission_forms#new
 edit_parent_permission_form GET    /parent_permission_forms/:id/edit(.:format)  parent_permission_forms#edit
      parent_permission_form GET    /parent_permission_forms/:id(.:format)       parent_permission_forms#show
                             PUT    /parent_permission_forms/:id(.:format)       parent_permission_forms#update
                             DELETE /parent_permission_forms/:id(.:format)       parent_permission_forms#destroy
    teacher_permission_forms GET    /teacher_permission_forms(.:format)          teacher_permission_forms#index
                             POST   /teacher_permission_forms(.:format)          teacher_permission_forms#create
 new_teacher_permission_form GET    /teacher_permission_forms/new(.:format)      teacher_permission_forms#new
edit_teacher_permission_form GET    /teacher_permission_forms/:id/edit(.:format) teacher_permission_forms#edit
     teacher_permission_form GET    /teacher_permission_forms/:id(.:format)      teacher_permission_forms#show
                             PUT    /teacher_permission_forms/:id(.:format)      teacher_permission_forms#update
                             DELETE /teacher_permission_forms/:id(.:format)      teacher_permission_forms#destroy
               trip_deposits GET    /trip_deposits(.:format)                     trip_deposits#index
                             POST   /trip_deposits(.:format)                     trip_deposits#create
            new_trip_deposit GET    /trip_deposits/new(.:format)                 trip_deposits#new
           edit_trip_deposit GET    /trip_deposits/:id/edit(.:format)            trip_deposits#edit
                trip_deposit GET    /trip_deposits/:id(.:format)                 trip_deposits#show
                             PUT    /trip_deposits/:id(.:format)                 trip_deposits#update
                             DELETE /trip_deposits/:id(.:format)                 trip_deposits#destroy
                   trip_fees GET    /trip_fees(.:format)                         trip_fees#index
                             POST   /trip_fees(.:format)                         trip_fees#create
                new_trip_fee GET    /trip_fees/new(.:format)                     trip_fees#new
               edit_trip_fee GET    /trip_fees/:id/edit(.:format)                trip_fees#edit
                    trip_fee GET    /trip_fees/:id(.:format)                     trip_fees#show
                             PUT    /trip_fees/:id(.:format)                     trip_fees#update
                             DELETE /trip_fees/:id(.:format)                     trip_fees#destroy
                   team_dues GET    /team_dues(.:format)                         team_dues#index
                             POST   /team_dues(.:format)                         team_dues#create
                new_team_due GET    /team_dues/new(.:format)                     team_dues#new
               edit_team_due GET    /team_dues/:id/edit(.:format)                team_dues#edit
                    team_due GET    /team_dues/:id(.:format)                     team_dues#show
                             PUT    /team_dues/:id(.:format)                     team_dues#update
                             DELETE /team_dues/:id(.:format)                     team_dues#destroy

```

How can I get the two lines to work?