Пытался настроить поведение при входе, следуя https://github.com/plataformatec/devise/#configuring-controllers.
с Rails 5.2.2, ruby 2.5.3, devise 4.6.1.
Я использовалuser_signed_in?с before_action в application_controller.rb, который делает запрос выбора и приводит к объекту current_user.
это средний пользователь вошел в систему?это ожидаемое поведение?
если это так, как я могу проверить вход пользователя в application_controller, где мне нужно установить значения уровня приложения на основе сведений о пользователе.
Помогите мне и исправьте меня, если я делаюнеправильно.
Не внесено никаких изменений в значение по умолчанию devise.rb
rout.rb
Rails.application.routes.draw do
resources :profiles
devise_for :users, controllers: { sessions: 'users/sessions' }
root to: "profiles#index"
end
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery prepend: true
before_action :simple_call, if: proc { user_signed_in? }
## USER BELOW LINE AS WELL BY COMMENTING ABOVE RESULTS SAME
#before_action :simple_call, if: proc { current_user.present? }
def simple_call
p '--------CURRENT_USER----'
p current_user
end
end
users / session_controller.rb
# frozen_string_literal: true
class Users::SessionsController < Devise::SessionsController
# before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
def create
p 'this line is printing after before action'
super do |resource|
p 'this is inside create'
end
end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end
end
Журнал во время входа в систему
Started GET "/" for 172.xx.xx.xx at 2019-02-13 19:25:57 +0530
Cannot render console from 172.xx.xx.xx! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Users::SessionsController#create as HTML
Parameters: {"utf8"=>"â", "authenticity_token"=>"Y01fmO/qtAbNO7QcS6lXc bOj0vSWXEnlYGlnrNT7TDOm4/yoJRWfSdknzpUMK2mKeMGrQaCEJa07Tn6I10Z2QQ==", "u ser"=>{"email"=>"k@t.com", "password"=>"[FILTERED]", "remember_me"=>"0 "}, "commit"=>"Log in"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."email " = ? ORDER BY "users"."id" ASC LIMIT ? [["email", "k@t.com"], ["LIMI T", 1]]
â³ app/controllers/application_controller.rb:3
"--------CURRENT_USER----"
#<User id: 1, email: "k@t.com", created_at: "2019-02-13 13:16:34", upd ated_at: "2019-02-13 13:16:34">
"this line is printing after before action"
"this is inside create"
Redirected to http://172.xx.xx.xx:3004/
Completed 302 Found in 141ms (ActiveRecord: 0.4ms)
ОБНОВЛЕНИЕ
См. Это обсуждение.https://github.com/plataformatec/devise/issues/4951
Полагаю, это будет исправлено в следующих выпусках.