How to change the location in a respond_with without overriding the behaviour when a model is not saved

106 views Asked by At

Given the following controller.

class Posts_controller < ApplicationController
    def create
        @post = Post.new(:params[:post])
        flash[:notice] = 'Post successfully saved' if @post.save
        respond_with(@post, :location => my_custom_url)
    end
end

In the event that a post is not saved, i.e. because it fails one or more validations, the controller goes to my_custom_url rather than rendering the 'new' view which it would do when no location would be given.

Is there any way to stop this behaviour from being overriden?

1

There are 1 answers

0
Arjan On BEST ANSWER

It turns out that the location is not changed after all, but that the code fails during url generation https://github.com/rails/rails/issues/2798.