[英]Routing Error when trying to update Devise user details, Rails 4
I am trying to fix issues with changing Devise user details in Rails 4 project. 我正在尝试修复在Rails 4项目中更改Devise用户详细信息的问题。 Based on this question
基于这个问题
Layout: 布局:
<div class="modal fade" id="user-profile" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog log-modal">
<div class="modal-content">
<%= render partial: "shared/profile" %>
</div>
</div>
</div>
_profile partial. _profile部分。
<%= form_for(@user, :url => { :action => "update_password",:controller =>"users" } ,remote: true, format: :json) do |f| %>
<div class="form-group">
<%= f.text_field :name,:class=>"user-input form-control", :id=>"user-name" ,:placeholder=> "Lietotājvārds*",:"data-parsley-group"=>"f1" %>
</div>
<div class="form-group">
<%= f.email_field :email ,:class=>"user-input form-control", :id=>"password",:placeholder=> "E-pasts *",:"data-parsley-group"=>"f2" %>
</div>
<div class="form-group">
<%= f.password_field :current_password, :autocomplete => "off" ,:class=>"user-input form-control", :id=>"password",:placeholder=> "Vecā parole* ",:"data-parsley-group"=>"f3" %>
</div>
<div class="form-group">
<%= f.password_field :password , :class=>"user-input form-control", :id=>"password",:placeholder=> "Jaunā parole* vismaz 8 simboli ", :"data-parsley-group"=>"f3" %>
</div>
<div class="form-group">
<%= f.password_field :password_confirmation , :class=>"user-input form-control", :id=>"password",:placeholder=> "Atkārtot paroli * vismaz 8 simboli ", :"data-parsley-group"=>"f3" %>
</div>
<button type="submit" class="blue-button btn btn-default">Apstiprināt</button>
<%end%>
My routes file: 我的路线档案:
Rails.application.routes.draw do
get 'banned/index'
get 'reusable/login'
get 'reusable/registration'
get 'reusable/password_recovery'
resources :menus
resources :blocked do
collection do
get 'checktoken'
get 'checkemail'
end
member do
post 'toggle'
post 'rev'
end
end
ActiveAdmin.routes(self)
scope "(:locale)", :locale => /lv|ee|ru/ do
devise_for :users, :controllers => {:registrations=> "registrations"}
resource :user, only: [:edit] do
collection do
patch 'update_password'
end
end
resources "successful-registration", :controller => :successful_registration, :as => :successful_registration
resources :replies do
member do
put "like", to: "replies#upvote"
put "dislike", to: "replies#downvote"
end
end
resources :reviews do
member do
put "like", to: "reviews#upvote"
put "dislike", to: "reviews#downvote"
put "downwote", to: "reviews#complaints"
end
end
resources :reports
resources :offers
resources :messages
resources :feedbacks
resources :girls do
collection do
get 'checktoken'
get 'checkemail'
end
member do
put "like", to: "girls#upvote"
put "dislike", to: "girls#downvote"
post 'toggle'
end
end
get 'sms/receive/', to: 'sms#receive'
root 'girls#index'
end
end
Log file: 日志文件:
Started POST "/ru/user/update_password" for 212.93.100.35 at 2015-10-03 14:08:12 +0300
ActionController::RoutingError (No route matches [POST] "/ru/user/update_password"):
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
What I tried: 我尝试了什么:
1) Restarted server 2) Tried to change order of the user routes. 1)重启服务器2)试图改变用户路由的顺序。
I have no other ideas to try. 我没有其他想法可以尝试。 Any help ?
有帮助吗? Thanks in advance.
提前致谢。
It seems you have routing for PATCH request ( patch 'update_password'
) but you are sending POST request. 您似乎有PATCH请求的路由(
patch 'update_password'
),但您正在发送POST请求。
Edit your routing file ( post 'update_password'
) or use PATCH request: 编辑路由文件(
post 'update_password'
)或使用PATCH请求:
<%= form_for(@user, :url => { :action => "update_password",:controller =>"users",method: "patch" },remote: true, format: :json) do |f| %>
As an addition to the answer, you should also be considering how Devise
would provide you with user account change functionality: 作为答案的补充,您还应该考虑
Devise
如何为您提供用户帐户更改功能:
# # Password routes for Recoverable, if User model has :recoverable configured
# new_user_password GET /users/password/new(.:format) {controller:"devise/passwords", action:"new"}
# edit_user_password GET /users/password/edit(.:format) {controller:"devise/passwords", action:"edit"}
# user_password PUT /users/password(.:format) {controller:"devise/passwords", action:"update"}
# POST /users/password(.:format) {controller:"devise/passwords", action:"create"}
If you use rake routes
, you'll see which Devise
routes you have access to, and which you're able to use. 如果您使用
rake routes
,您将看到您有权访问哪些Devise
路线,以及您可以使用哪些路线。
If you're looking to use Devise
to handle this (which it appears you are), you can either use the above routes (which will become accessible if you add :recoverable
to your User
model Devise
definitions), or if you call them directly. 如果您希望使用
Devise
来处理此问题(您看起来是这样),您可以使用上述路由(如果您添加:recoverable
可以访问:recoverable
到User
模型Devise
定义),或者直接调用它们。
If you want to add / edit Devise
routes explicitly, you'll be able to do the following: 如果要显式添加/编辑
Devise
路由,您将能够执行以下操作:
devise_for :users, controllers: { registrations: "registrations" } do
patch "passwords/update" => "passwords#update", :as => :password_update
end
-- -
I also see a lot of your routes being specifically defined. 我还看到很多路线都是专门定义的。 Although nothing wrong with this, it's very inefficient and actually prevents your app from being able to harness its true potential.
虽然没有任何问题,但效率非常低,实际上会阻止您的应用程序利用其真正的潜力。
Here are some examples I would recommend you investigate: 以下是我建议您调查的一些示例:
#config/routes.rb
resources :reusable, only: [] do
collection do
get :login
get :registration
get :password_recovery
end
end
Another one is to define multiple resources
in one batch ... 另一个是在一个批次中定义多个
resources
......
resources :reports, :offers, :messages, :feedbacks
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.