ruby-on-rails-3respond-with

respond_with do not redirect to index.html.erb


I need help with the responder respond_with, 'cause when I create a new post (in this case) It doesn't redirect to the location specified. What can be?. This is the piece of my code that creates a new post but It's be redirected to create.html.erb and not the index.html.erb that I specified.

 def create
    @post = Post.create(params[:post])
    respond_with(@post, :status => :created, :location => posts_url)
 end

Solution

  • try to use "redirect_to" (from ACIIcasts - Controllers in Rails 3):

    redirect_to @result, :notice => "Successfully converted original data."
    

    If you are not confortable with the solution i found a workaround in a similar post: link

    def convert
      @result = Result.find(params[:id])
      @result.convert_original_data
      success = @result.save
      respond_with(@result) do |format|
        format.html {redirect_to result_path(@result) } if success
      end
    end