Reputation: 81
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]
Upvotes: 1
Views: 813
Reputation: 81
config.api_only = false
allow Middleware to Rack::MethodOverride
I have config.api_only = true
and that's was my problem.
Upvotes: 1
Reputation: 61
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
Upvotes: 0
Reputation: 1
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| %>
Upvotes: 0