1

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
Dagosi
  • 948
  • 2
  • 11
  • 25

2 Answers2

1

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
Community
  • 1
  • 1
shil88
  • 1,449
  • 1
  • 11
  • 13
  • It works, but the reason that I'm using respond_with is to avoid the specification of each format. So, Why the location attr doesn't work?. Thanks for help. – Dagosi Dec 27 '11 at 15:50
0

You don't need to supply location. It will do it automagically for you.

All you need to do is...

respond_with @post

It will set the correct status and redirect you to the posts_url.

Altonymous
  • 783
  • 7
  • 25