I’m stuck in creating a form for editing users in my admin panel. The administrator should be able to edit user roles and delete them, so I created a form but unfortunately I get an error
ActiveRecord::RecordNotFound (Couldn't find User without an ID):
routes.rb
Rails.application.routes.draw do
namespace :admin do
root to: 'users#index'
resources :users
get 'users/index'
get 'users/new'
get 'users/edit'
get 'users/delete'
end
get 'home', to: 'home#index'
devise_for :users, controllers: {
sessions: 'users/sessions'
}
devise_scope :user do
root to: 'users/sessions#new'
get 'sign_in', to: 'users/sessions#new'
get '/users/sign_out', to: 'users/sessions#destroy'
get 'search_users', to: 'users/sessions#search_users'
end
end
app/controllers/admin/users_controller.rb
class Admin::UsersController < Admin::BaseController
def index
#@users = User.all
@users = User.find(params[:id])
end
end
app/views/admin/users/index.html.erb
<div class="container-fluid admin-container">
<div class="admin-h2-container">
<h2 class="admin-h2">Zarządzanie użytkownikami</h2>
</div>
<div class="admin-table">
<table class="table table-striped" style="width: 80%;">
<thead>
<tr>
<th class="admin-table">No</th>
<th class="admin-table">Username</th>
<th class="admin-table">Imię</th>
<th class="admin-table">Nazwisko</th>
<th class="admin-table">Uprawnienia</th>
</tr>
</thead>
<body>
<% @users.each do |user| %>
<tr>
<td>
<%= simple_form_for [:admin, @users] do |f| %>
<div class="form-inputs">
<%= f.input :id, input_html: {readonly: true } %>
<%= f.input :username, input_html: {readonly: true } %>
<%= f.input :first_name, input_html: {readonly: true } %>
<%= f.input :last_name, input_html: {readonly: true } %>
<%= f.input :role, input_html: {readonly: true } %>
</div>
<% end %>
</td>
</tr>
<% end %>
</body>
</table>
</div>
</div>
I’m guessing the problem is somewhere in the routs but I have no ideas on how to fix it. Can I count on help?