我上传了几张图片(来自http://localhost:3000/choices/new
),这些图片可以正常工作,但是我试图在保存后重新导向到:http://localhost:3000/choices
。Rails 4 - 为什么我保存后不能重定向?
这里是我的控制器:
#app/controllers/choices_controller.rb
def create
@choice = Choice.new(choice_params)
@choice.filename = params[:filename].titleize
if @choice.save
respond_to do |format|
format.html { redirect_to choices_path }
format.json { head :no_content }
end
end
end
在Rails控制台,它输出:
Redirected to http://localhost:3000/choices
Completed 302 Found in 58ms (ActiveRecord: 52.8ms)
然而, “新” 的页面保持不变。任何关于如何正确重定向的想法,或许是通过一条说明“图片上传成功”的Flash消息?
非常感谢!
它是异步请求吗? –
是的,这是一个异步请求。 – Dodinas
为什么它是异步请求,因为你只是想做重定向? –