any_login icon indicating copy to clipboard operation
any_login copied to clipboard

Multiple models support

Open kenzo-tanaka opened this issue 2 years ago • 9 comments

Related: https://github.com/igorkasyanchuk/any_login/pull/44

This change will support multiple models.

What I fixed

  • Accept multiple model setting by klass_names
  • Display multiple login forms
  • Pass class name by params[:as]
  • In controller, find model name by params[:as] and login.

Configuration

config.klass_names = ['User', 'Staff']

Demo

https://user-images.githubusercontent.com/33926355/190950814-c81a11da-b758-43c9-ab31-801ae618d805.mov

I checked this behavior at this repository. https://github.com/kenzo-tanaka/rails_sandbox/pull/8

kenzo-tanaka avatar Sep 18 '22 12:09 kenzo-tanaka

Hello @igorkasyanchuk @rbclark , Could you review this PR ?

It was difficult to resolve conflicts on https://github.com/igorkasyanchuk/any_login/pull/44, so I created this new PR.

kenzo-tanaka avatar Sep 19 '22 04:09 kenzo-tanaka

@kenzo-tanaka good start, but I have a question, could you please extend at least dummy/devise app with another model? I want to try it on your branch.

igorkasyanchuk avatar Sep 19 '22 08:09 igorkasyanchuk

Thanks for the reply. I will try it.

kenzo-tanaka avatar Sep 21 '22 13:09 kenzo-tanaka

@igorkasyanchuk Sorry for the delay in responding.

could you please extend at least dummy/devise app with another model?

I am having trouble understanding how to proceed this. Do I just create a new model under the test/rails_app/devise directory and fix the any_login settings?

kenzo-tanaka avatar Oct 19 '22 13:10 kenzo-tanaka

I am having trouble understanding how to proceed this. Do I just create a new model under the test/rails_app/devise directory and fix the any_login settings?

Correct, specifically in the test/rails_apps/devise/app/models folder. You can set it up the same way it is in your demo with a user and a staff model if you wish.

rbclark avatar Oct 19 '22 13:10 rbclark

Thanks for the reply. Is it possible to use the rails or rake commands in the test/rails_app/devise directory?

I get an error when I run the following commands, is there a workaround?

$ cd test/rails_apps/devise/
$ rails db:create    
rails aborted!
NameError: uninitialized constant Bundler
/Users/tanakakenzou/Documents/personal/any_login/test/rails_apps/devise/config/application.rb:7:in `<top (required)>'
/Users/tanakakenzou/Documents/personal/any_login/test/rails_apps/devise/Rakefile:4:in `require_relative'
/Users/tanakakenzou/Documents/personal/any_login/test/rails_apps/devise/Rakefile:4:in `<top (required)>'
bin/rails:4:in `<main>'

Caused by:
LoadError: cannot load such file -- rails/commands
bin/rails:4:in `<main>'
(See full trace by running task with --trace)

kenzo-tanaka avatar Oct 19 '22 13:10 kenzo-tanaka

Thanks for the reply. Is it possible to use the rails or rake commands in the test/rails_app/devise directory?

I get an error when I run the following commands, is there a workaround?

You just need to preface your commands with bundle exec,

➜  devise git:(master) pwd
/Documents/any_login/test/rails_apps/devise
➜  devise git:(master) bundle exec rails db:create
Database 'db/development.sqlite3' already exists
Database 'db/test.sqlite3' already exists

rbclark avatar Oct 19 '22 13:10 rbclark

@igorkasyanchuk @rbclark I added a new model to the devise sample app. Please check it.

kenzo-tanaka avatar Oct 20 '22 13:10 kenzo-tanaka

Thank you @kenzo-tanaka, this is super close to being ready to merge. The only remaining issue is the klass_name problem.

rbclark avatar Dec 22 '22 17:12 rbclark