0

I finally came to ask this question since I found no answer and it kept bothering me. What's the reason behind this behavior ? Is it REST-thingy-driven :) ?

I found this "workaround" but no explanation : How to make a render :edit call show the /edit in the address bar

Thanks


EDIT

My question was not that well written, sorry. Why the default Rails behavior is not to redirect to the edit template? That would feel more logical, to me at least :)

Community
  • 1
  • 1
ddidier
  • 1,298
  • 1
  • 12
  • 15

1 Answers1

2

render doesn't redirect, so there's no reason the URL bar address would change.

The default update method looks like this:

  # PUT /posts/1
  # PUT /posts/1.json
  def update
    @post = Post.find(params[:id])

    respond_to do |format|
      if @post.update_attributes(params[:post])
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

The URL is /posts/1, which is what displays in the URL bar. If update_attributes fails, e.g., a validation error, it renders the "edit" template, with no redirect.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • @c_inconnu Because saving a model in flash is potentially expensive, especially since the default flash is limited to max cookie size, and a serialized model can be quite large. Also, IMO there's no good *reason* to change the URL. – Dave Newton Nov 27 '12 at 22:27