Problem retrieving user id

I have a problem, I use a find.params[:id] to display a user from a list, and then I want to edit that information. I have a separate action for the edit, named change_user_details, and I retrieve the user id the same way I do for the audit_user with find.params[:id]. The problem is that the action change_user_details does not want to retrieve the current viewed user id. It gives the error Couldn't find User without an ID. Here is the code of the two actions and the two forms.

def audit_user     @user = User.find(params[:id]) end

def change_user_details   @user = User.find(params[:id]) end

<h4>Username: <%= @user.username %><h4> <h4>Email: <%= @user.email %><h4> <h4>IP: <%= @user.user_ip %><h4> <h4>First Name: <%= @user.firstname %><h4> <h4>Last Name: <%= @user.lastname %><h4>

<%= link_to('Change', :action => 'change_user_details') %>

<%= link_to('Back', :action => 'list_users') %>

<h1>Editing User Information</h1>

<% form_tag :action => 'update_user', :id => @user do %>

  <p><label for="user_firstname">Firstname</label><br/>   <%= text_field 'user', 'firstname' %></p>

  <p><label for="user_lastname">Last Name</label><br/>   <%= text_field 'user', 'lastname' %></p>

  <p><label for="user_email">Email</label><br/>   <%= text_field 'user', 'email' %></p>

  <%= submit_tag("Update")%>

<% end %>

<%= link_to('Back', :action => 'audit_user') %>

Hi

Perhaps you can take a look at activescaffold...

CCH

Thanks, took care of the problem :slight_smile:

I have a problem, I use a find.params[:id] to display a user from a list, and then I want to edit that information. I have a separate action for the edit, named change_user_details, and I retrieve the user id the same way I do for the audit_user with find.params[:id]. The problem is that the action change_user_details does not want to retrieve the current viewed user id. It gives the error Couldn't find User without an ID.

Right, because params[:id] is empty.

Here is the code of the two actions and the two forms.

def audit_user     @user = User.find(params[:id]) end

def change_user_details   @user = User.find(params[:id]) end

<h4>Username: <%= @user.username %><h4> <h4>Email: <%= @user.email %><h4> <h4>IP: <%= @user.user_ip %><h4> <h4>First Name: <%= @user.firstname %><h4> <h4>Last Name: <%= @user.lastname %><h4>

<%= link_to('Change', :action => 'change_user_details') %>

This doesn't pass an id. You need to explicitly pass it:

  <%= link_to 'Change', :action => 'change_user_details', :id => @user %>

Yep, it worked. Before that I used a newly created session to track the id. But it worked. Thanks a lot.