我想知道如何在设计config.rb中进行类似的事情。
if request.subdomain == 'app'
config.case_insensitive_keys = [:username]
elsif request.subdomain == 'support'
config.case_insensitive_keys = [:email]
end
这里的用途是我希望系统用户只能使用他们的employee_id(用户名)登录,因为他们的电子邮件地址可以出现在多个帐户中,所以我需要一种登录并注册的方式,而无需捕获设计电子邮件验证他们,但是我希望后端组只能通过电子邮件(我和未来的开发者)登录,因为那里最多可以有多个电子邮件的用户
由于某种原因尝试删除数据库时,此操作失败了吗?
堆栈跟踪
/Users/taurenltd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/type.rb:27: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/taurenltd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/type/adapter_specific_registry.rb:9: warning: The called method `add_modifier' is defined here
rails aborted!
SyntaxError: /Users/taurenltd/Desktop/Development/roadze-base/config/initializers/devise.rb:301: syntax error, unexpected end-of-input, expecting `end'
/Users/taurenltd/Desktop/Development/roadze-base/config/environment.rb:5:in `<main>'
/Users/taurenltd/Desktop/Development/roadze-base/bin/rails:9:in `<top (required)>'
/Users/taurenltd/Desktop/Development/roadze-base/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:drop => db:load_config => environment
(See full trace by running task with --trace)
taurenltd@Shawns-MBP roadze-base % rails db:drop db:create db:migrate
/Users/taurenltd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/type.rb:27: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/taurenltd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/type/adapter_specific_registry.rb:9: warning: The called method `add_modifier' is defined here
rails aborted!
NameError: undefined local variable or method `request' for main:Object
Did you mean? require
/Users/taurenltd/Desktop/Development/roadze-base/config/initializers/devise.rb:55:in `block in <main>'
/Users/taurenltd/Desktop/Development/roadze-base/config/initializers/devise.rb:5:in `<main>'
/Users/taurenltd/Desktop/Development/roadze-base/config/environment.rb:5:in `<main>'
/Users/taurenltd/Desktop/Development/roadze-base/bin/rails:9:in `<top (required)>'
/Users/taurenltd/Desktop/Development/roadze-base/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
答案 0 :(得分:0)
使用以下代码块完成此工作
def self.matches?(request)
if request.subdomain.present? && request.subdomain == 'app'
config.case_insensitive_keys = [:username]
elsif request.subdomain.present && request.subdomain == 'support'
config.case_insensitive_keys = [:email]
end
end