Reputation: 11
I'm creating a app. I've created a User Controller, and successfully created New and Create methods. Running the rails console, I can bring up any ID that I've created. I don't understand when I try to edit from the users/index.html page I'm not directed to /users/id/edit It's just being directed to /users
inspecting the params that are passed, it does show that the correct ID when I click edit for that particular User.
Routes:
Prefix Verb URI Pattern Controller#Action
users_index GET /users/index(.:format) users#index
welcome_index GET /welcome/index(.:format) welcome#index
macros GET /macros(.:format) welcome#macros
faqs GET /faqs(.:format) welcome#faqs
root GET / welcome#index
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
UsersController:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(set_user_params)
if @user.save
redirect_to users_path
else
end
end
def index
@users = User.all
end
def edit
raise params.inspect
@user = User.find(params[:id])
end
private
def set_user_params
params.require(:user).permit(:name, :email, :team, :password)
end
end
index.html
<div> <%= link_to "Create New Agent", new_user_path %></div>
<% @users.each.with_index(1) do |user, index| %>
<div class="list_of_agents">
<%= user.name %><br>
<%= user.team %><br>
<%= user.id %><br>
<%= link_to "Edit", edit_user_path(user.id) %><br>
</div>
<% end %>
Upvotes: 1
Views: 584
Reputation: 1601
Please change the edit
url to
<%= link_to "Edit", edit_user_path(user) %>
Upvotes: 1