[英]How to use custom view to update user via devise? (rails gem)
I have 2 custom views I built for devise, 1 changes the password the other updates other custom information. 我有2个为设计构建的自定义视图,1更改密码,其他更新其他自定义信息。 The password update worked, so I copied the method for the second view, however I am getting an error when submitting the data 密码更新工作,所以我复制了第二个视图的方法,但是我在提交数据时收到错误
No route matches [PATCH] "/users/discovery_settings/update"
which does not make sense because my route is 这是没有意义的,因为我的路线是
devise_for :users, controllers: {registrations: 'users/registrations'}
as :user do
end
get 'users/discovery_settings' => 'users#discovery_settings'
post 'users/discovery_settings/update' => 'users#update_discovery'
in my controller i user the same method that works for password updates 在我的控制器中,我使用与密码更新相同的方法
def update_discovery
@user = User.find(current_user.id)
if @user.update(user_params)
# Sign in the user by passing validation in case their password changed
sign_in @user, :bypass => true
redirect_to root_path
else
render "edit"
end
end
then i call it in my form_for view 然后我在我的form_for视图中调用它
<%= form_for(@user, :url => { :action => "update_discovery" }, html: {class: "form floating-label"}) do |f| %>
Any ideas how to fix the routing error? 有任何想法如何解决路由错误? I am at a lost as to why it is looking for "patch" when i have already specified "post" 当我已经指定“帖子”时,我迷失了为什么它正在寻找“补丁”
The error's telling you. 错误告诉你。 You have a POST route and the update is asking for a PATCH route. 你有一个POST路由,更新是要求PATCH路由。
try with patch instead of post : 尝试使用补丁而不是帖子 :
patch 'users/discovery_settings/update' => 'users#update_discovery'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.