简体   繁体   English

当重定向Rails无法在浏览器上呈现html响应时

[英]When redirect Rails is not rendering html response on browser

When I try to use this method 当我尝试使用这种方法

  def create
    @ticket = current_user.creator.build(ticket_params)
    if @ticket.save!
      flash[:success] = "Thanks! I'll be in touch soon!"
      redirect_to @ticket
    else
      render :root
    end
  end

It saves a perfect ticket record in the database. 它将完美的工单记录保存在数据库中。 And return the 'show' page's html as response, but in the browser is still in the same page . 并返回“显示”页面的html作为响应, 但在浏览器中仍在同一页面中

the response and two request created by this method is: 此方法创建的响应和两个请求是:

在此处输入图片说明

My form: 我的表格:

= simple_form_for(@ticket, html: { class: 'form-horizontal', multipart: true  }, remote: true) do |f|

#.....

  = f.submit 'Criar Ticket', class: 'btn btn-primary'

You are setting remote to true in your form, therefore making a javascript request. 您正在表单中将remote设置为true,因此发出了javascript请求。 However your controller is responding as if it was an html request by redirecting. 但是,您的控制器通过重定向来响应,好像它是html请求一样。 Why are you setting remote to true? 为什么将remote设置为true? If there's not a good reason simply remove remote: true and things will work. 如果没有充分的理由,只需删除remote: true ,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM