Question: I am trying to update users **via AJAX** from my index view, so I have the following view:

```
<% @users.each do |user| %>
    <tr>
      <td><%= user.email %></td>
      <td>
        <%= form_for [:admin, user], :remote => true, :authenticity_token => true, :format => :json do |f| %>
          <%= f.radio_button :approved, true, :checked => user.approved, :id => "user_approved_#{user.id}", :onclick => "this.form.submit();"%> Yes
          <%= f.radio_button :approved, false, :checked => !user.approved, :id => "user_not_approved_#{user.id}", :onclick => "this.form.submit();" %> No
        <% end %>
      </td>
    </tr>
  <% end %>

```

And I have the controller update method that looks like this:

```
def update
    @user = User.find(params[:id])
    respond_to do |format|
      if @user.update(user_params)
        format.json { render nothing: true }
      else
        format.json { render nothing: true}
      end
    end
  end

```

Even though the record gets correctly updated, it renders an empty page with the following URL: `admin/users/2.json` or whatever id is the record that was just updated.

Any idea how can I make it just render the index view where the form was submitted from?

Answer: 
**JS**

Firstly, I don't understand *exactly* what you're trying to achieve

I surmise that you're trying to capture the updated data you've just sent? If this is the case, I would not use the `json` MIME-type; instead, I would just send a plain `JS` request.

The JSON mime type is mainly for the likes of `API`s - where noted objects are called back using the `json` structure. You'll be setting yourself up for a headache if you try and do things other than show the JSON data in your response 

---

**Render**

You *may* be looking for the following:

```
#app/views/controller/your_view.html.erb
<%= form_for [:admin, user], :remote => true, :authenticity_token => true do |f| %>

#app/controllers/users_controller.rb
Class UsersController < ApplicationController
   def update
      respond_to do |format|
         format.js   { render :index }
         format.json { render json: index_path.to_json }
      end
   end
end

```

---

**Fix**

From what you're saying, it seems you want to be able to do the following:

```
#app/assets/javascripts/application.js
$(document).on("ajax:success", "#your_form", function(data, status, xhr){
    document.location.href= data; //have to find a way to use data's index path reference
});

```
Add this javascript snippet on your page:

```
$("form").on("ajax:complete", (xhr, status) ->
  location.reload();
)

```

You might want to use ajax:success and ajax:error instead of ajax:complete.

If AJAX is not used then you can redirect to the index page after an update:

```
def update
  @user = User.find(params[:id])
  @user.update(user_params)
  redirect_to :action => :index
end

```