Reputation: 953
I am trying to fix issues with changing Devise user details in Rails 4 project. 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.
<%= 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.
I have no other ideas to try. Any help ? Thanks in advance.
Upvotes: 1
Views: 533
Reputation: 76784
As an addition to the answer, you should also be considering how Devise
would provide you with user account change functionality:
# # 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.
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.
If you want to add / edit Devise
routes explicitly, you'll be able to do the following:
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 :reports, :offers, :messages, :feedbacks
Upvotes: 1
Reputation: 2508
It seems you have routing for PATCH request (patch 'update_password'
) but you are sending POST request.
Edit your routing file (post 'update_password'
) or use PATCH request:
<%= form_for(@user, :url => { :action => "update_password",:controller =>"users",method: "patch" },remote: true, format: :json) do |f| %>
Upvotes: 2