# Problem retrieving user id

**URL:** <https://www.ruby-forum.com/t/problem-retrieving-user-id/117371>\
**Category:** Rails\
**Created:** [October 16, 2007, 12:58pm UTC](https://www.ruby-forum.com/t/problem-retrieving-user-id/117371 "2007-10-16T12:58:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2007, 12:58pm UTC](https://www.ruby-forum.com/t/problem-retrieving-user-id/117371/1 "2007-10-16T12:58:55Z")

</div>

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

#### Username: \<%= @user.username %\>

#### 

#### Email: \<%= @user.email %\>

#### 

#### IP: \<%= @user.user\_ip %\>

#### 

#### First Name: \<%= @user.firstname %\>

#### 

#### Last Name: \<%= @user.lastname %\>

#### 

\<%= link\_to(‘Change’, :action =\> ‘change\_user\_details’) %\>  
|  
\<%= link\_to(‘Back’, :action =\> ‘list\_users’) %\>

# Editing User Information

\<% form\_tag :action =\> ‘update\_user’, :id =\> @user do %\>

Firstname  
 \<%= text\_field 'user', 'firstname' %\>

Last Name  
 \<%= text\_field 'user', 'lastname' %\>

Email  
 \<%= text\_field 'user', 'email' %\>

\<%= submit\_tag(“Update”)%\>

\<% end %\>

\<%= link\_to(‘Back’, :action =\> ‘audit\_user’) %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2007, 1:51pm UTC](https://www.ruby-forum.com/t/problem-retrieving-user-id/117371/2 "2007-10-16T13:51:06Z")

</div>

Hi

Perhaps you can take a look at activescaffold…

CCH

> **[Rails... Rails... Rails](http://cch4rails.blogspot.com)**
>
> Chee Chong Hwa aka CCH, a Malaysian Chief Software Architect blogs on his experiences with Ruby on Rail running on Win2003 Server+Apache 2.26 environment since 2007. Flirted briefly with Ubuntu 9.04 in 2009. Since January 2017, now using RubyMine...

On Oct 16, 6:58 pm, “removed\_email\_address@domain.invalid”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/problem-retrieving-user-id/117371/3 "2007-10-16T14:50:25Z")

</div>

Thanks, took care of the problem 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/problem-retrieving-user-id/117371/4 "2007-10-16T15:57:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 16, 2007, 3:29pm UTC](https://www.ruby-forum.com/t/problem-retrieving-user-id/117371/5 "2007-10-16T15:29:03Z")

</div>

On 10/16/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

> #### Username: \<%= @user.username %\>
> 
> #### 
> 
> #### Email: \<%= @user.email %\>
> 
> #### 
> 
> #### IP: \<%= @user.user\_ip %\>
> 
> #### 
> 
> #### First Name: \<%= @user.firstname %\>
> 
> #### 
> 
> #### Last Name: \<%= @user.lastname %\>
> 
> #### 
> 
> \<%= 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  
%\>
