I have a controller that looks like this:
def new
@title = "Add New Post"
@post = Post.new
end
def create
@title = "Add New Post"
@post = Post.new(params[:post])
if @post.save
flash[:success] = @post.name+" successfully added. Thank you!"
redirect_to @post
else
render 'new'
end
end
The problem is that if a user successfully creates a new post, then decides to change something by pressing the Back button and hitting "Save" again, I get duplicate entries.
What is the best way to prevent something like this? I thought that the create action is automatically a POST request in Rails, so the browser should say something like "Are you sure you want to resend the data, bla bla bla..."
Running rake routes does show this:
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new