我现在在Ruby应用程序中使用Devise gem。 似乎密码方法不起作用,因为在某种程度上,设计控制器有点修改。当我键入/ users / password / new时,它会返回到根目录。
我遵循了一个教程,但现在我坚持这个非常重要的方法,我必须提供给人们。
passwords_controller.rb文件位于controllers / users / password_controller.rb中。
代码是
class Users::PasswordsController < Devise::PasswordsController
prepend_before_filter :require_no_authentication
# Render the #edit only if coming from a reset password email link
append_before_filter :assert_reset_token_passed, only: :edit
# GET /resource/password/new
def new
self.resource = resource_class.new
end
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(resource_params)
yield resource if block_given?
if successfully_sent?(resource)
respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
else
respond_with(resource)
end
end
(这是一个典型的设计控制器内容)
我的user.rb模型如下。
...
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:google_oauth2] #, :confirmable
...
我在此目录中有查看文件。
views/users/passwords/create.html.erb, edit.html.erb, new.html.erb
views/users/sessions/new.html.erb
views/users/registrations/edit.html.erb, create.html.erb
路由文件就像这样
devise_for :users, controllers: { passwords: "users/passwords", sessions: "users/sessions", registrations: "users/registrations", omniauth_callbacks: "users/omniauth_callbacks" }
每当我输入“http://localhost:3000/users/password/new”时,它都会回到root。
这是我的路线档案。
new_user_session GET /users/sign_in(.:format) users/sessions#new
user_session POST /users/sign_in(.:format) users/sessions#create
destroy_user_session GET /users/sign_out(.:format) users/sessions#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/google_oauth2/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#:action
user_password POST /users/password(.:format) users/passwords#create
new_user_password GET /users/password/new(.:format) users/passwords#new
edit_user_password GET /users/password/edit(.:format) users/passwords#edit
PATCH /users/password(.:format) users/passwords#update
PUT /users/password(.:format) users/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST|GET /:controller(/:action(/:id))(.:format) :controller#:action
root GET / landings#index
我去localhost时得到的日志:3000 / users / password / new就是这样。
在2015-10-06 04:11:58开始GET“/ users / password / new”for :: 1 +0900用户处理:: PasswordsController #new as HTML重定向到localhost:3000过滤链停止为: is_login呈现或重定向完成302在2ms内找到(ActiveRecord:0.0ms)这是我在发布地址后立即得到的日志
如果你们有任何提示,请告诉我! 最好
答案 0 :(得分:0)
我通过追加/ users / password / edit修复它吗?reset_password_token = aaaaaa 也许这是设计错误。