我正在尝试修复在Rails 4项目中更改Devise用户详细信息的问题。基于this问题
布局:
<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。
<%= 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%>
我的路线档案:
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
日志文件:
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'
我尝试了什么:
1)重启服务器 2)试图改变用户路线的顺序。
我没有其他想法可以尝试。有帮助吗? 提前谢谢。
答案 0 :(得分:2)
您似乎有PATCH请求(patch 'update_password'
)的路由,但您正在发送POST请求。
编辑路由文件(post 'update_password'
)或使用PATCH请求:
<%= form_for(@user, :url => { :action => "update_password",:controller =>"users",method: "patch" },remote: true, format: :json) do |f| %>
答案 1 :(得分:1)
作为答案的补充,您还应该考虑how Devise
would provide you用户帐户更改功能:
# # 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"}
如果您使用rake routes
,则会看到您有权访问哪些Devise
路由,以及您可以使用哪些路由。
如果您希望使用Devise
来处理此问题(您看来是这样),您可以使用上述路线(如果您将:recoverable
添加到User
,这些路线就可以访问1}}模型Devise
定义),或者如果你直接调用它们。
如果您想明确添加/修改Devise
路线,您将能够执行以下操作:
devise_for :users, controllers: { registrations: "registrations" } do
patch "passwords/update" => "passwords#update", :as => :password_update
end
-
我也看到很多路线都是专门定义的。虽然没有任何问题,但效率非常低,实际上会阻止您的应用程序利用其真正的潜力。
以下是我建议您调查的一些示例:
#config/routes.rb
resources :reusable, only: [] do
collection do
get :login
get :registration
get :password_recovery
end
end
另一个是define multiple resources
in one batch ...
resources :reports, :offers, :messages, :feedbacks