Created
March 30, 2017 15:04
-
-
Save jmercedes/e995adeeabe2ad9da140ac999646ddf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for(@user, :url => { :action => "update_password", :controller =>"users", method: "patch" }) do |f| %> | |
<div class="field"> | |
<%= f.label :password, "Password" %><br /> | |
<%= f.password_field :password, :autocomplete => "off" %> | |
</div> | |
<div class="field"> | |
<%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation %> | |
</div> | |
<div class="action_container"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/user/update_password" for ::1 at 2017-03-30 10:19:59 -0400 | |
ActionController::RoutingError (No route matches [GET] "/user/update_password"): | |
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' | |
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call' | |
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch' | |
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call' | |
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' | |
railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app' | |
railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call' | |
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged' | |
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged' | |
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged' | |
railties (4.2.6) lib/rails/rack/logger.rb:20:in `call' | |
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call' | |
rack (1.6.5) lib/rack/methodoverride.rb:22:in `call' | |
rack (1.6.5) lib/rack/runtime.rb:18:in `call' | |
activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' | |
rack (1.6.5) lib/rack/lock.rb:17:in `call' | |
actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call' | |
rack (1.6.5) lib/rack/sendfile.rb:113:in `call' | |
railties (4.2.6) lib/rails/engine.rb:518:in `call' | |
railties (4.2.6) lib/rails/application.rb:165:in `call' | |
rack (1.6.5) lib/rack/lock.rb:17:in `call' | |
rack (1.6.5) lib/rack/content_length.rb:15:in `call' | |
rack (1.6.5) lib/rack/handler/webrick.rb:88:in `service' | |
/Users/juan/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service' | |
/Users/juan/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run' | |
/Users/juan/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
resources :tasks | |
devise_for :users | |
resource :user, only: [:edit] do | |
member do | |
patch 'update_password' | |
end | |
end | |
root 'tasks#index' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_action :authenticate_user! | |
def edit | |
@user = current_user | |
end | |
def update_password | |
@user = User.find(current_user.id) | |
if @user.update(user_params) | |
# Sign in the user by passing validation in case their password changed | |
bypass_sign_in(@user) | |
redirect_to root_path | |
else | |
render "edit" | |
end | |
end | |
private | |
def user_params | |
# NOTE: Using `strong_parameters` gem | |
params.require(:user).permit(:password, :password_confirmation) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment