Rails: Creating an index view for a devise user
Devise hides its own controllers and views in the gem library directory. You can pull the views into your project for editing, but there's nothing similar for controllers. See the Devise documentation for some examples.
It's pretty easy to generate your own controller and views for this:
config/routes.rb:
# NOTE: put this after the 'devise_for :users' line
resources :users, only: [:index]
app/controllers/users_controller.rb:
class UsersController < ApplicationController
def index
@users = User.all
end
end
app/views/users/index.html.erb:
<ul>
<% @users.each do |user| %>
<li><%= user.name %></li>
<% end %>
</ul>
This is a minimalist example that should work for you.
You might want to consider using ActiveAdmin, if you don't need to style it like the public portions of your app. Saves you the trouble of coding, styling, and securing a lot of basic record management utlities that apps need. I use ActiveAdmin and then roll my own controllers/views/routes as above for presenting a user list in the public portions of the app.
Devise will handle registration and login/logout. It will not do anything else. Index is a typical controller action within rails. When you generated a user scaffold did you add any extra parameters? Rails getting started has the basic documentation. Scroll down to the 6th section about scaffolds. When you generate a scaffold you create a Model, a View, and a Controller. Section 7 of that tutorial generates a model from scratch. In your case a user model may have a string for a name and a string for an email. A model can have many attributes like boolean values or integers. (You will want to add devise attributes for authentication like password, but that can be added later.) So try generating a scaffold again but with rails generate scaffold user name:string email:string
. This will add name and email columns to your user model. From there the scaffold should set you up with the default actions in the controller and basic views. Then you should have your index action.