Rails 5 Resource Routing Error Only In Production

152 Views Asked by At

I have a perfectly normal resource defined by resources :products.

Update works fine in development, on my laptop on pony. Production is on a server I don't have a lot of control of, using phusion. Whenever I try to update it redirects mysteriously, giving me a 404. This is what is in the log:

64d8] Completed 200 OK in 57ms (Views: 9.6ms | ActiveRecord: 2.0ms)
I, [2018-08-03T13:42:22.444552 #2652091]  INFO -- : [dde252e5-5750-4f63-9fd2-b02a882c864c] Started PATCH "/products/578" for > 154.20.31.78 at 2018-08-03 13:42:22 -0700
F, [2018-08-03T13:42:22.445282 #2652091] FATAL -- : [dde252e5-5750-4f63-9fd2-b02a882c864c]
F, [2018-08-03T13:42:22.445332 #2652091] FATAL -- : [dde252e5-5750-4f63-9fd2-b02a882c864c] ActionController::RoutingError (No route matches [PATCH] "/578"):

As you can see, it seems to be changing the route somewhere I have no access to.

EDIT: The form starts:

<%= form_with model: product, local: true do |form| %>

And populates correctly for /products/id/edit. This produces the html:

<form enctype="multipart/form-data" action="/products/578" accept-charset="UTF-8" method="post">
  <input name="utf8" type="hidden" value="&#x2713;" />
  <input type="hidden" name="_method" value="patch" />
  <input type="hidden" name="authenticity_token" value="g+oaySVsX4QLZSvII9xbEZo3j0lGChrXSHhMUdUyJ+3eZEUK6iC6QK4sa1SkdBX6f2vvH2HXlN+rR5lzQOmDWA==" />

This is the relevant method in the controller, which, judging from logging experiments, never seems to be touched. Curiously enough, the forms which trigger format.js work perfectly well.

def update
  verify_admin
  respond_to do |format|
    @product.update(product_params)
    if @product.save
      save_picture if params[:product][:picture_file]
      if params[:commit] == 'Add/Edit'
        format.html { redirect_to products_url(@product) }
      else
        format.js { render inline: 'location.reload()' }
      end
    else
      format.html { render :edit }
    end
  end
end
0

There are 0 best solutions below