Rails simple_form_for update action routing error [POST] with id

701 views Asked by At

I try to update customer object via simple_form_for with Rails 6

From show.html.erb I have <%= render partial: "form", object: @customer, as: 'customer' %>

My form example: _form.html.erb

<%= simple_form_for customer, remote: true, url: customer_path(customer), method: :patch do |f| %>

I don't know why, Rails throw RoutingError

ActionController::RoutingError (No route matches [POST] "/customers/1"):

My routing:

resources :customers, only: %i[show create new update]
3

There are 3 answers

0
Tomas On BEST ANSWER

config.api_only = false allow Middleware to Rack::MethodOverride

I have config.api_only = true and that's was my problem.

1
Ajay Birla On

Try the following, no need to specify the method, because rails enough smart to identify whether the object is new or persisted. And check your routes as well.

<%= simple_form_for customer, remote: true do |f| %>

1
Kemal AKIN On

You can use edit partial and remove the parameters url: customer_path(customer) and method: :patch. And simple form for automatically send request put path