I tried to let the user from http://localhost:3000/account/password
edit their passwords.
But I get this in the Rails log:
Started GET "/users/password/edit" for ::1 at 2017-03-30 10:10:32 +0800
Processing by Users::PasswordsController#edit as HTML
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Here is something that I tried.
rails g devise:controllers users
rails g devise:views users
Routes
devise_for :users, controllers: {
registrations: 'users/registrations',
sessions: 'users/sessions',
passwords: 'users/passwords',
confirmations: 'users/confirmations'
}
devise_scope :user do
get 'sign_up', to: 'users/registrations#new'
get 'sign_in', to: 'users/sessions#new'
delete 'sign_out', to: 'users/sessions#destroy'
get 'account/users', to: 'users/registrations#edit'
get 'account/password', to: 'users/passwords#edit'
end
Controller
app/controllers/users/passwords_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def edit
# super
@user = current_user
end
def update
# super
@user = User.find(current_user.id)
if @user.update_with_password(user_params)
bypass_sign_in(@user)
redirect_to account_users_path, notice: "恭喜,密码更改成功。"
else
render :edit
end
end
protected
def user_params
params.require(:user).permit(:password, :password_confirmation)
end
end
Views
app/views/users/passwords/edit.html.erb
<%= link_to "Edit Password", account_password_path %>
Any help will be welcome.