Rails Devise allows 1 person to register - ruby-on-rails

I am having a Rails app for personal use and it uses Devise for authentication. I want there is only one user for my app. In other words, how do I disable registration in Devise after there is already 1 user registered ?
I am thinking about creating a custom method in controller. But is there any good way to do this ?

You want to remove the :registerable option in the model. Then create your single account in your seed.rb and then just seed your app. No need to complicate things just for your own use.

Related

CRUD actions on a Devise User model - Rails 5

I'm working on a project that has a User Devise model and an Admin Devise model, and I want an Admin to be able to perform CRUD on the User model.
I've set up both Devise models following the Devise Wiki's How to Setup Multiple Devise User Models guide (including step 4 - exposing the scoped controllers).
This has given me the Devise views and controllers for confirmations, passwords, registrations, sessions and unlocks, but no users_controller to add CRUD actions to.
Could I simply create a users_controller and make sure it uses the correct users table in the database, or should I add CRUD actions to the registrations_controller?
Is the above advisable, or is there a more elegant way of setting up a CRUD interface for an Admin to be able to manage the User model?
Any help would be much appreciated.
Devise works only with sign_up/sign_in process. It assumes not only simple user creation, but some more things, like email sending.
So if you want to create/update/destroy users you need to create separate UsersController. It is better to add an admin namespace to it

Devise and discourse: Seperate devise users for vendors and users or just one devise for users?

I'm building a website, where vendors can have their own separate website on. There is vendors and normal users.
The goal is to have a closed profile page w. login for both, where a vendor can edit his website, check out stats and more. A normal user is also able to login to mark different vendor's websites as favourites and check out newest post on the forum. So what is important here is: They booth need to be on my Discourse forum, but I'd like to avoid a Vendor to have a login both for vendor and for a user (Signing up twice).
http://www.discourse.org/ has SSO ability for devise, but im not sure if it allows for two different devise models.
Should I:
Create one devise-model for both, called Users? (And have a boolean or integer if User is a vendor/has vendor-access?)
Or:
Separate them: One for Users and one for Vendors?
I haven't tested out if Discourse allows for two devise-models, since Discourse is the easiest to set up in production-mode. But I need your advice: Can I use Single sign-on for devise with two different devise models? Is it the preferable way? Or is there other ways than this I haven't noticed? Like adding a user to a vendor, or something?
Using rails 5
We can achieve this by managing role field. We can make entry on the time of sign_up in role field that user is normal user or vendor. After create this we check user_role can in after_sign_up_path and redirect to path accordingly.
for this refer gem rolify
please correct me if getting any thing wrong.

Create separate session for rails admin login

I’m using Rails 4.2.1 and Devise and rails_admin and I’m quite new to Rails.
I need to add rails admin to my project. I need a separate login For rails admin. (I don't want to add a new column user for that. As admin and normal users are different) For that I added a new model Admin. I used devise for creating views and models. But now I need to add routes in routes for admin user having only sign in feature(No need for registration). Now I have all those features(registration,...). I also need a separate session apart from the user session. As I logout user, adminuser is also logging out.
To get seperate session please make changes in devise.rb
config.sign_out_all_scopes = false

Split devise edit user registration into 2 separate forms to change email and change password?

I've searched topics but this exact question doesn't come up. Is it possible to separate the Devise user form to make it 2 separate forms?
change email
change password?
You only have to create a simple CRUD, as in any other case. it is also posible to generate the view that devise uses and/or override the controllers.
https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface
Managing your users is not really devise related, devise only really handles authentication.

How Do I Create a User Profile With Devise?

I really like how devise offers an easy to use registration system out of the box but I'm having trouble extending it to do what I need. I need to create a public user profile for each user that shows their information like name, email, bio, and more info. I've done this in the past before with a users/show function but since devise doesn't provide any easily editable controllers, I'm having trouble figuring out how to do this. I've already run rails generate devise:views to copy the devise views to my app but I don't know where to go from here. Any help would be much appreciated.
Sounds like you want users to update their profile at the same time they create their account? If so, you can setup an associated Profile model with the User model. Using accepts_nested_attributes_for you can then create a record for the nested model on devise user registration submit/creation.
Here's a great screencast covering nested models and I also suggest you search other devise relate SO posts as this question has been discussed before.
There is an alternative approach, that is simpler to implement — only allow registered users edit/update their profile. This way you don't have to alter the Devise views and you can setup the various CRUD actions via a separate non-devise controller.
Throw in an Access Control List (ACL) solution such as CanCan (there are other alternatives too!) and you can even allow other users view profiles but deny access to edit/destroy etc.

Resources