I have this controller
def usersedit
@user = User.find_by id: params[:id]
end
def usersupdate
@user = User.find_by id: params[:id]
if @user.update(post_params)
redirect_to action: :users
else
render 'usersedit'
end
end
And this form in the view in usersedit.html.erb
<%= form_for :user, url: {action: "usersupdate"}, method: :patch do |f| %>
but when I submit the form this error appears
No route matches [PATCH] "/admin/usersupdate"
My routes code is:
Prefix Verb URI Pattern Controller#Action
root GET / pages#home
admin_index GET /admin/index(.:format) admin#index
admin_grades GET /admin/grades(.:format) admin#grades
pages_home GET /pages/home(.:format) pages#home
pages_register GET /pages/register(.:format) pages#register
pages_create POST /pages/create(.:format) pages#create
pages_login GET /pages/login(.:format) pages#login
pages_logging POST /pages/logging(.:format) pages#logging
pages_logout GET /pages/logout(.:format) pages#logout
GET /activate/:user/:hash(.:format) pages#activate
remember POST /remember(.:format) pages#remember
reactivation POST /reactivation(.:format) pages#reactivation
admin_documents GET /admin/documents(.:format) admin#documents
admin_users GET /admin/users(.:format) admin#users
GET /admin/usersedit/:id(.:format) admin#usersedit
admin_usersupdate POST /admin/usersupdate(.:format) admin#usersupdate
Help please.
change the method in the form method: :post
your header of form
form_for :user, url: {action: "usersupdate"}, :method => :POST do |f|
I had the same problem, you'll need to update your routes.rb file correctly.
I'm guessing the line in your routes file where you've defined this path starts with "post", try changing that to "patch".
Inside of config/routes.rb
change:
post "admin/usersupdate" => "admin#usersupdate", :as => "admin/usersupdate"
to:
patch "admin/usersupdate" => "admin#usersupdate", :as => "admin/usersupdate"
Everything works swimmingly for me after I made this change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With