How to destroy rolify and/or rename devise user model? - ruby-on-rails

I have an Ruby 2 Rails 4 application generated by Rails Composer with Devise and Rolify. I am trying to rename the Devise User model, so I wanted to destroy it and generate it. However, I am getting errors trying to do so related to Rolify. I’ve made several attempts to destroy Rolify with no success and cannot get past that point so that I can work with Devise.
I am going to show several attempts to resolve this problem, along with the errors I get. Each attempt started with a fresh copy of the application. I show the error streams, only.
I basically have two questions:
1. How do I destroy rolify?
2. Is there a better way to rename the devise User model? I thought I found another way but, for the life of me, I can’t find it again..
Destroy rolify, the result being a failed attempt to subtract role.rb after it was removed.
rails destroy rolify Role User
invoke active_record
remove app/models/role.rb
invoke rspec
remove spec/models/role_spec.rb
invoke factory_girl
remove spec/factories/roles.rb
subtract app/models/role.rb
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/thor-0.19.1/lib/thor/actions/inject_into_file.rb:98:in `binr
ead': No such file or directory - D:/BitNami/rubystack-2.0.0-11/projects/workingapp/app/models/role.rb (Errno::ENOENT)
Destroy devise model, generate devise model and generate rolify
rails destroy devise user
rails generate devise device
rails generate rolify Role Device.
invoke active_record
The name 'Role' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.
Destroy devise model, generate devise model, delete app/models/role.rb and generate rolify
rails destroy devise user
rails generate devise device
del app/models/role.rb
rails generate rolify Role Device.
D:/BitNami/rubystack-2.0.0-11/ruby/lib/ruby/gems/2.0.0/gems/activesupport-4.0.3/lib/active_support/inflector/methods.rb:
226:in `const_get': uninitialized constant Role (NameError)

I haven't been able to find anyway to do this. Backing off Rolify just doesn't seem to work. I've decided to use Rails Composer to create the application without Devise, Rolify and CanCan, then generate each of them individually with my desired model names and configurations. Then, I can migrate all of the code of written into that application and modify it. It's not an easy answer, but it seems to be the best choice...

Related

Devise model without devise routes

I have two Rails projects sharing some files, one is the actual app and the other one is the admin tool for the app. They share migrations, models, some config, etc. The admin tools is ActiveAdmin 1.0.0-pre2 and Rails' version is 4.2.
I have two Devise models, User and AdminUser. In the app project, there's no route for admin_user and I want to keep it that way, but if I don't add:
devise_for :admin_users
to the routes file, I get all sort of strange errors, such as:
ActionView::Template::Error: undefined method `admin_user_confirmation_url' for #<ActionDispatch::Routing::RoutesProxy:0x007fc613ecde08>
or:
Could not find a valid mapping for <AdminUser ...>
whenever I'm creating an AdminUser in the app project (sample data generation).
How can I achieve having a devise model, without the routes?
If you just want a model for Admin, to Have some methods and data, remove all devise entries (database_authenticatable, etc.) from the admin user migration and model, and use it as a plain activerecord model. If you need any specific devise modules, you can add them one by one. But the devise modules you add will likely require the controller and routes to be present.
What I would do if I were you:
Merge the two applications into one.
Create a new field in the User migration and call it "role", with default value "user"
Use Cancan or something similar to set different permissions depending on the role ("user" or "admin"). For example users with role "user" cannot view any of the admin pages. And this way whoever is admin in your website, doesn't need to have a separate model/account for loging in to active admin.
Don't get me wrong, I just can't think of a good reason to keep the two sides as different projects. It will only add problems to your logic and implementation and you will have to constantly be passing information around. I actually use ActiveAdmin in the way I explained above and everything works like a charm.

RoR Active Admin adding Users

This might be a very simple questions as I am just getting started with RoR and been doing as much learning through resources as possible. Basically I am using Active Admin to handle the admin portion of my application. What I am wondering about is creating a user model. I know Active Admin uses Devise for its autherzation so if run rails generate active_admin:resource Userit should create the user model the same way as if I ran it with Devise correct?
The end goal is to have the main front end page be a login for users that are created by the admin on Active Admin (no sign up from the front end) that will lead them to the secure information like Profile, orders, what ever.
What you're looking to do (assuming that you want to separate out the idea of Admin Users versus regular users) is first generate the new devise model as you normally would:
rails generate devise user
Then create a resource to manage them within active admin
rails generate active_admin:resource User
The rest is a standard devise integration assuming the pages are outside the scope of Active Admin.

Ruby on Rails devise - No route matches [GET] "/users"

First time using devise I'm a little confused. I've followed a tutorial that manually goes through authentication so I have some understanding of Rails in this respect.
Normally when you create a scaffold for a User you get a Users controller with all the methods for showing, editing, adding etc. users, which can be accessed through the browser via http://localhost:3000/users/[action].
I have destroyed the User scaffold and started again with devise (rails generate devise User) but this does not create a controller at all. Going to http://localhost:3000/users/ gives the error No route matches [GET] "/users".
Am I supposed to create my own controller? Where do I go from here?
I think you did not initialized devise. You should probably run
rails generate devise:install
And then generate model for User by running
rails generate devise User

Getting Paper_trail + Rails_admin + Devise with Multiple 'user' models

I am developing an app in Rails 3, currently I use Devise as the login and Rails_admin as the admin panel with Paper_trail tracking all changes made by 'user' model... Problem is I have two user models, User and Admin. So a line of code in rails_admin.rb (initiliazer) to setup Paper_trail to track history:
config.audit_with :paper_trail, User
Is there any way to have paper_trail monitor changes made by both User and Admin, or can it only follow one model? I notice that even when it is set like this, and I make a change from within Rails_admin as an admin, the change says it was made by the User with the same ID as the admin that made the change.
The best way to handle this is to install CanCan, remove my Admin Model, and take advantage of using Multiple Roles within a single model for the current situation.

Using Devise, how can I have different configuration options for admins and users?

Using Devise, I have an admin model and a user model. I want to specify different configuration options for each model. At the moment, all of my Devise configuration is in /config/initializors/devise.rb. How can I do this?
You'll need two things for each: route helpers (which will end up in routes.rb) and devise field helpers (which will end up in your two models).
When you run rails generate devise user and rails generate devise admin, you should get setup with what you need for both to get started.
Oh, and chase it down with rake db:migrate, as depending on your needs, various columns will get added to both tables.
(If you're asking for setting different global configuration options for different models, I'm not sure how to go about doing that, actually, if it's even possible.)

Resources