Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 设计重置密码未知格式_Ruby On Rails 4_Devise_Devise Recoverable - Fatal编程技术网

Ruby on rails 4 设计重置密码未知格式

Ruby on rails 4 设计重置密码未知格式,ruby-on-rails-4,devise,devise-recoverable,Ruby On Rails 4,Devise,Devise Recoverable,我使用Desive和simple_token_身份验证。查询的基本格式是json。 my routes.rb: Rails.application.routes.draw do devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords' } devise_scope :user do post "user

我使用Desive和simple_token_身份验证。查询的基本格式是json。 my routes.rb:

Rails.application.routes.draw do
  devise_for :users, controllers: {
        registrations: 'users/registrations',
        passwords: 'users/passwords'
  }
  devise_scope :user do
    post "users/reset_password" => "users/registrations#reset_password", as: 'reset_password', defaults: { format: :json }
  end
  resources :cities, :institution_types, defaults: { format: :json } do
    resources :institutions, only: [:index, :new, :create]
  end
  resources :institutions, only: [:show, :edit, :update, :destroy]
  root 'persons#profile'
end
Rails.application.routes.draw do

  devise_for :users, controllers: {
        registrations: 'users/registrations',
        passwords: 'users/passwords'
  }
  devise_scope :user do
    post "users/reset_password" => "users/registrations#reset_password", as: 'reset_password'
  end

  resources :cities, :institution_types do
    resources :institutions, only: [:index, :new, :create]
  end
  resources :institutions, only: [:show, :edit, :update, :destroy] do
    resources :proposals, only: [:index, :create]
  end
  get 'institutions/:id/check' => 'institutions#check', as: 'check_path'
  root 'persons#profile'
end
为了响应localhost:3000/users/reset_password.json的请求,一切都正常工作,它会出现在带有链接的电子邮件消息中。单击链接时,将打开默认视图“设计/密码/编辑”。我输入一个新密码,单击“提交”,然后出现一个错误:

ActionController::用户中的未知信息::密码控制器#更新

但在控制台中,我看到密码已成功更改

Started PUT "/users/password" for ::1 at 2016-03-13 16:40:40 +0500
Processing by Users::PasswordsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"MZVw3cwbkW+qgySSzKJLyfvNI0ZgKrG1AyTAYAQsIlQAK7mYyxoGlnlemjmajcBZz/zhL3Krmr7fhiNUqtahcQ==", "user"=>{"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"}
  User Load (1.1ms)  SELECT  "users".* FROM "users" WHERE "users"."reset_password_token" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["reset_password_token", "0733ad150b4a7d695e5125a79271f96fd7fa140d195480dcb215ecc03c048c6c"]]
   (0.2ms)  BEGIN
  SQL (0.6ms)  UPDATE "users" SET "encrypted_password" = $1, "updated_at" = $2, "reset_password_token" = $3, "reset_password_sent_at" = $4 WHERE "users"."id" = $5  [["encrypted_password", "$2a$10$2uUu/Rv/c01HMxvHfDhdlunlNGejtXyVRtUQwEf2SpYOe0qlRIdlC"], ["updated_at", "2016-03-13 11:40:40.272568"], ["reset_password_token", nil], ["reset_password_sent_at", nil], ["id", 3]]
   (12.4ms)  COMMIT
   (0.2ms)  BEGIN
  SQL (0.9ms)  UPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5  [["last_sign_in_at", "2016-03-13 11:39:10.385224"], ["current_sign_in_at", "2016-03-13 11:40:40.292489"], ["sign_in_count", 5], ["updated_at", "2016-03-13 11:40:40.295309"], ["id", 3]]
   (6.4ms)  COMMIT
Completed 406 Not Acceptable in 158ms (ActiveRecord: 21.8ms)

ActionController::UnknownFormat (ActionController::UnknownFormat):
在U controller.rb中:

class Users::PasswordsController < Devise::PasswordsController
  def after_resetting_password_path_for(resource)
    #super(resource)
    root_path
  end
end
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
    respond_to :json
    protect_from_forgery with: :exception

    skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
    acts_as_token_authentication_handler_for User, fallback: :none

end
我得到了同样的错误:

Started PUT "/users/password" for ::1 at 2016-03-14 17:23:32 +0500
Processing by Users::PasswordsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"QT+j6cLGLyZ1NU3V8aNcXmsmPEAaXxlWizhkaC1z8DqNq85ft6bHNgFKW0r26OzOUjLEPzoYVIQ0khFycRQbxg==", "user"=>{"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"}
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."reset_password_token" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["reset_password_token", "2a2c916a0611f1944c36f27643edc322e2625284ebf189083774832ac66ee90b"]]
   (0.3ms)  BEGIN
  SQL (0.4ms)  UPDATE "users" SET "encrypted_password" = $1, "updated_at" = $2, "reset_password_token" = $3, "reset_password_sent_at" = $4 WHERE "users"."id" = $5  [["encrypted_password", "$2a$10$5wrUqD9gr.ZF990WcScPJuzT9ftwxg6xqptkLCKugeQfbrjoQd.5C"], ["updated_at", "2016-03-14 12:23:32.247207"], ["reset_password_token", nil], ["reset_password_sent_at", nil], ["id", 3]]
   (1.0ms)  COMMIT
   (0.2ms)  BEGIN
  SQL (0.4ms)  UPDATE "users" SET "current_sign_in_at" = $1, "sign_in_count" = $2, "updated_at" = $3 WHERE "users"."id" = $4  [["current_sign_in_at", "2016-03-14 12:23:32.252785"], ["sign_in_count", 2], ["updated_at", "2016-03-14 12:23:32.253976"], ["id", 3]]
   (0.9ms)  COMMIT
Completed 406 Not Acceptable in 97ms (ActiveRecord: 3.7ms)

ActionController::UnknownFormat (ActionController::UnknownFormat):

事实证明,我在他的应用程序中没有注意到_controller.rb行respond_to:json。 在应用程序_controller.rb中:

class Users::PasswordsController < Devise::PasswordsController
  def after_resetting_password_path_for(resource)
    #super(resource)
    root_path
  end
end
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
    respond_to :json
    protect_from_forgery with: :exception

    skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
    acts_as_token_authentication_handler_for User, fallback: :none

end
class ApplicationControllerProc.new{| c | c.request.format=='application/json'}
作为用户的\u令牌\u身份验证\u处理程序\u,回退::无
结束

事实证明,我在他的应用程序中没有注意到\u controller.rb行respond\u to:json。 在应用程序_controller.rb中:

class Users::PasswordsController < Devise::PasswordsController
  def after_resetting_password_path_for(resource)
    #super(resource)
    root_path
  end
end
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
    respond_to :json
    protect_from_forgery with: :exception

    skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
    acts_as_token_authentication_handler_for User, fallback: :none

end
class ApplicationControllerProc.new{| c | c.request.format=='application/json'}
作为用户的\u令牌\u身份验证\u处理程序\u,回退::无
结束

将此
默认值:{format::json}
替换为
,默认值:{format:%w{json html}}
并尝试从路由和try@AmitSharma,我更改了路由,但得到相同的错误。整个文本不适合注释,因此我在问题中添加了它自己,将此
默认值:{format::json}
替换为
,默认值:{format:%w{json html}}
,并尝试从路由和try@AmitSharma,我更改了路由,但得到相同的错误。整个文本不适合评论,所以我在问题中加了一句