Why does Rails want to return "head :no_content" for JSON PUT requests? -



Why does Rails want to return "head :no_content" for JSON PUT requests? -

after run rails generate scaffold user generated controller function in rails 3.2.11 updating user looks this:

def update @user = user.find(params[:id]) respond_to |format| if @user.update_attributes(params[:user]) format.html { redirect_to @user, notice: 'user updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @user.errors, status: :unprocessable_entity } end end end

the line i'm curious returning head :no_content successful json update request. i've done googling, guessing sort of restful property, not homecoming updated object, couldn't find claimed case.

why default, versus returning json representation of user object post-update?

good question, apparently purpose homecoming http status code 200 empty body, see this discussion. maybe brevity or security purposes. head :no_content seems create http response 200 (success) empty body, returning response header:

status code:200 ok

see this related question.

ruby-on-rails

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -