I want to know the meaning of the serialize_options key passed by the response_with argument in Device.

Asked 2 years ago, Updated 2 years ago, 72 views

https://github.com/plataformatec/devise/blob/1a0192201b317d3f1bac88f5c5b4926d527b1b39/app/controllers/devise/sessions_controller.rb

in the

respond_with(resource,serialize_options(resource))

In the end, I think we have passed the process to .erb.
respond_with does not work

def serialize_options(resource)
    methods=resource_class.authentication_keys.dup
    methods=methods.keys if methods.is_a?(Hash)
    methods<<:password if resource.respond_to?(:password)
    { methods:methods, only: [:password]}
  end

So, I'm creating a Hash with methods and only as keys, and respond_with seems to take this Hash as an argument...what do these two keys mean?

ruby-on-rails ruby devise

2022-09-30 11:22

1 Answers

I don't fully understand it, but I somehow understood the role by looking at this commit (especially the test).

https://github.com/plataformatec/devise/commit/3cedba1de8345b5f5f9055acd5513e893ed8d497

The methods use authentication_keys in config/initializers/device.rb.

The default is:email.

#config.authentication_keys=[:email]

If you change this to :subdomain, it seems that user.subdomain is used instead of user.email during authentication.(Probably)

config.authentication_keys=[:subdomain]

Also, wouldn't it be possible to use GitHub's blame or history to trace the commit log back, or to slowly debug using pry or RubyMine to solve other unclear points?

That's all for your information.


2022-09-30 11:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.