Ruby on Rails Devise - Setup - Already Used? - ruby-on-rails

Working through the setup for Devise.
Running
rails generate devise admin
since admin seems to be the user model setup in my app where I now what it to be SSO auth but I get
The name 'Admin' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check or --force to skip this check and run this generator again.
is it OK to force/ignore this? or ?

Related

Apartment: uninitialized constant Tenant (NameError)

I am using the Apartment Gem for the first time for Multitenancy in a Ruby on Rails project. I am trying to create multiple tenants for users in your digital library Rails application.
I am using Devise Gem for the authentication of the application, and I have generated the and I have generated config file by running the code below in my terminal
rails generate devise:install
I have also generated a User model for Devise using the code below in my terminal
rails generate devise User
And for the Apartment Gem, I have installed it and generated the config file by running the code below in my terminal
bundle exec rails generate apartment:install
I have also configured the config/initializers/apartment.rb initializer file as needed using the documentation provided, but when I run the command below in my terminal
rails generate devise:views
to generate the views for Devise, I get the error below
uninitialized constant Tenant (NameError)
I have tried to figure out the cause of the issue, but I still haven't been fortunate to get it fixed. I need some help. Thank you in advance.
I later realized that the issue was from the configuration that I made initially to Apartment Gem's config/initializers/apartment.rb initializer file.
After creating the User model, I also added it to the excluded models list in the config/initializers/apartment.rb initializer file.
config.excluded_models = %w[Tenant User]
I was supposed to instead replace Tenant in the excluded models list with the User model.
config.excluded_models = %w[User]
And that fixed the issue for me.
N/B: If I named the model name of my subdomain for the multiple tenants as Tenant, then I the configuration can be left like this
config.excluded_models = %w[Tenant]
But for my case, I named the model name of my subdomain for the multiple tenants as User
That's all.
I hope this helps

Rails 5.1 Installing ActiveAdmin without Devise and a custom User model

So I have a question, about using ActiveAdmin without Devise, the documentation is not clear on this for my needs and I see a lot of people not answering this question clearly. And to be clear, I am using Rails 5.1
To install without using devise you run
rails g active_admin:install --skip-users
In my case, I already have a User class and my own authentication. The docs say:
If you want to use an existing user class, provide it as an argument:
rails g active_admin:install User
this is where the confusion for me lies. Since, I already have a User class and DO NOT want to use Devise, and the generator above does install Devise, would I run
rails g active_admin:install User --skip-users
or
rails g active_admin:install --skip-users
The official documentation states:
After installing the gem, you need to run the generator. Here are your options:
If you don’t want to use Devise, run it with --skip-users:
rails g active_admin:install --skip-users
Further reading:
https://activeadmin.info/0-installation.html#setting-up-active-admin
After that create your own User model, as described in the docs. You can handle authentication as described here:
https://activeadmin.info/1-general-configuration.html#authentication
Normally it incorporates defining some controller method like authenticate_admin_user!.

Adding api to an existing rails project with devise

I need to add some api for moobile to my existing project in rails. I am using devise gem for authentication. The first api needed are user registration, login, profile update , some posting feature etc.I am following https://github.com/lynndylanhurley/devise_token_auth this to create api, but it creates user.rb and migration as well as a duplicate routes. Am I doing something wrong. Please help me to solve the issue . Thanks in advance
I have added devise token authentication for api. Also created a seperate application controller for api's. All the api controller extends this application controller. The api routes starts with /api/
Documentation says:
A model will be created in the app/models directory. If the model already exists, a concern will be included at the top of the file.
And
A migration file will be created in the db/migrate directory. Inspect the migrations file, add additional columns if necessary, and then run the migration:
So
Can I use this gem alongside standard Devise?
Yes! But you will need to enable the support of separate routes for standard Devise.
https://github.com/lynndylanhurley/devise_token_auth#can-i-use-this-gem-alongside-standard-devise
Personally, I wouldn't use Devise for your authentication but would create a custom one next to Devise just for your API. Devise can become a bit buggy later on in the process when using it for API-authentication. Then for your authorization you could use Pundit. You might want to use Regulator next to it for controller namespaced authorization polices(it's not under development anymore, but it does the job).
There's a nice tutorial about this process:
API Tutorial
Here you can find Pundit:
Pundit Gem
And here's the Regulator gem:
Regulator Gem

Rails: Conditionally enable / disable devise modules

I am building my own dynamic backend in top of Ruby on Rails framework. I would like to know if there is a way to conditionally enable or disable Devise modules such as registerable, confirmable, omniauthable, ...
What I did try almost worked except I had to restart the rails server to take in consideration my modification but in my case I would like the system to work with boolean defined in the database.
For example:
devise :registerable if registerable_module.enabled? # boolean fetched from database
Thanks for your help

Devise error using rails 3.0.1 on sign_in action

I'm developing a rails 3 app using rails 3.0.1 and I'd like to use devise for user auth, but when I login with a user email, I get this error:
RuntimeError in Devise/sessionsController#create
In order to use respond_with, first you need to declare the formats your controller responds to in the class level
I installed devise using Gemspec.
I have the same issue yesterday and today i up a ticket and they fix the problem. Make a bundle update to have the fix version.
Make sure this is the first entry in your routes file
devise_for :users
Consider upgrading to Rails 3.0.3

Resources