Gustavo Rego
Gustavo Rego

Reputation: 335

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.

the response and two request created by this method is:

enter image description here

My form:

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

#.....

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

Upvotes: 0

Views: 241

Answers (1)

boulder
boulder

Reputation: 3276

You are setting remote to true in your form, therefore making a javascript request. However your controller is responding as if it was an html request by redirecting. Why are you setting remote to true? If there's not a good reason simply remove remote: true and things will work.

Upvotes: 1

Related Questions