我使用Devise auth token gem来验证我的rails应用程序的某些部分。但是当我尝试登录时,我收到以下错误:
POST http://localhost:3000/auth/sign_in 500(内部服务器错误)
以下是完整的跟踪:
在2018-05-30 09:29:36为10.12.4.5开始POST“/ auth / sign_in” +0500由DeviseTokenAuth处理:: SessionsController #create as JSON参数:{“login”=>“admin”,“password”=>“[FILTERED]”, “session”=> {“login”=>“admin”,“password”=>“[已过滤]”}}已完成500 14ms内部服务器错误(ActiveRecord:0.0ms)
NoMethodError(
的未定义方法`each'):
devise_token_auth(0.1.43) 应用程序/控制器/ devise_token_auth / application_controller.rb:35:在
params_for_resource' devise_token_auth (0.1.43) app/controllers/devise_token_auth/sessions_controller.rb:129:in
resource_params'devise_token_auth(0.1.43) 应用程序/控制器/ devise_token_auth / sessions_controller.rb:13:在create' actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in
send_action'actionpack(5.1.6) lib / abstract_controller / base.rb:186:在process_action' actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in
process_action'actionpack(5.1.6)中 lib / abstract_controller / callbacks.rb:20:inblock in process_action' activesupport (5.1.6) lib/active_support/callbacks.rb:131:in
run_callbacks'actionpack(5.1.6) lib / abstract_controller / callbacks.rb:19:在process_action' actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in
process_action'中 actionpack(5.1.6) lib / action_controller / metal / instrumentation.rb:32:在block in process_action' activesupport (5.1.6) lib/active_support/notifications.rb:166:in
块中的乐器' activesupport(5.1.6) lib / active_support / notifications / instrumenter.rb:21:ininstrument' activesupport (5.1.6) lib/active_support/notifications.rb:166:in
instrument'actionpack(5.1.6) lib / action_controller / metal / instrumentation.rb:30:在process_action' actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in
process_action'中 activerecord(5.1.6) LIB / active_record / railties / controller_runtime.rb:22:在process_action' actionpack (5.1.6) lib/abstract_controller/base.rb:124:in
进程'actionpack(5.1.6) lib / action_controller / metal.rb:189:在dispatch' actionpack (5.1.6) lib/action_controller/metal.rb:253:in
dispatch'actionpack(5.1.6)中 lib / action_dispatch / routing / route_set.rb:49:indispatch' actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in
serve' actionpack(5.1.6)lib / action_dispatch / routing / mapper.rb:16:inblock in <class:Constraints>' actionpack (5.1.6) lib/action_dispatch/routing/mapper.rb:46:in
serve'actionpack(5.1.6) lib / action_dispatch / journey / router.rb:50:inblock in serve' actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in
each' actionpack(5.1.6)lib / action_dispatch / journey / router.rb:33:inserve' actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in
call'warden(1.2.7)lib / warden / manager.rb:36:inblock in call' warden (1.2.7) lib/warden/manager.rb:35:in
catch'监狱长(1.2.7) lib / warden / manager.rb:35:incall' rack (2.0.5) lib/rack/etag.rb:25:in
call' rack(2.0.5)lib / rack / conditional_get.rb:38:incall' rack (2.0.5) lib/rack/head.rb:12:in
call'activerecord(5.1.6) lib / active_record / migration.rb:556:在call' actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in
块中调用' activesupport(5.1.6)lib / active_support / callbacks.rb:97:inrun_callbacks' actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in
调用'actionpack (5.1.6)lib / action_dispatch / middleware / executor.rb:12:在call' actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in
调用' actionpack(5.1.6) lib / action_dispatch / middleware / show_exceptions.rb:31:incall' railties (5.1.6) lib/rails/rack/logger.rb:36:in
call_app'railties (5.1.6)lib / rails / rack / logger.rb:24:inblock in call' activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in
块中的标记' activesupport(5.1.6)lib / active_support / tagged_logging.rb:26:intagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in
标记为'railties(5.1.6) lib / rails / rack / logger.rb:24:incall' actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in
call'actionpack (5.1.6)lib / action_dispatch / middleware / request_id.rb:25:incall' rack (2.0.5) lib/rack/runtime.rb:22:in
call'activesupport(5.1.6) LIB / active_support /缓存/策略/ local_cache_middleware.rb:27:在call' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in
调用'actionpack (5.1.6)lib / action_dispatch / middleware / static.rb:125:在call' rack (2.0.5) lib/rack/sendfile.rb:111:in
调用'rack-cors(1.0.2) lib / rack / cors.rb:97:incall' railties (5.1.6) lib/rails/engine.rb:522:in
call'puma(3.11.4) lib / puma / configuration.rb:225:incall' puma (3.11.4) lib/puma/server.rb:632:in
handle_request'puma(3.11.4) lib / puma / server.rb:446:在process_client' puma (3.11.4) lib/puma/server.rb:306:in
块中运行'puma(3.11.4) lib / puma / thread_pool.rb:120:在`spawn_thread中的块'
如何解决错误?
application_controller.rb:
class ApplicationController < ActionController::API
include DeviseTokenAuth::Concerns::SetUserByToken
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:login, :first_name, :patronymic, :last_name, :email, :password, :password_confirmation) }
devise_parameter_sanitizer.permit(:sign_in) { |u| u.permit(:login, :password) }
devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(:password, :password_confirmation, :current_password) }
end
end
user.rb:
class User < ActiveRecord::Base
self.table_name = 'DASHBOARD.V_L_USERS'
self.primary_key = 'user_id'
devise :database_authenticatable, :validatable, :authentication_keys => [:login]
include DeviseTokenAuth::Concerns::User
has_many :permission_references, as: :source
accepts_nested_attributes_for :permission_references, :allow_destroy => true
has_many :user_roles
has_many :spr_dashboards, foreign_key: 'l_users_id'
accepts_nested_attributes_for :user_roles, :allow_destroy => true
def email_required?
false
end
def password_required?
false
end
def is_participant
(read_attribute(:is_participant) == "Y")
end
def is_participant=(value)
write_attribute(:is_participant, (value == "1") ? "Y" : "N")
end
def children_users_ids
ActiveRecord::Base.connection.select_values <<-SQL.strip_heredoc
SELECT l_users_id_right
FROM DASHBOARD.V_L_USERS_RIGHTS
WHERE l_users_id = #{user_id}
SQL
end
end
routes.rb中:
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'auth'
end
答案 0 :(得分:0)
看起来devise_parameter_sanitizer中不支持块。 https://github.com/lynndylanhurley/devise_token_auth/issues/758#issuecomment-280797969