# How get the value user id?

**URL:** <https://www.ruby-forum.com/t/how-get-the-value-user-id/117547>\
**Category:** Rails\
**Created:** [October 17, 2007, 10:58pm UTC](https://www.ruby-forum.com/t/how-get-the-value-user-id/117547 "2007-10-17T22:58:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmnmm7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@mmnmm7](https://www.ruby-forum.com/u/mmnmm7)\
**Post date:** [October 17, 2007, 10:58pm UTC](https://www.ruby-forum.com/t/how-get-the-value-user-id/117547/1 "2007-10-17T22:58:04Z")

</div>

Hi, all!

I’m new to RoR.  
Please help me. 🙂

======================================================  
[/controller/login.rb]  
…  
def find\_id  
if request.post?  
member = params[:member]  
@is\_member = Member.find(:first, :conditions =\> [‘name=? and  
email=?’, member[:name], member[:email]])  
if @is\_member  
redirect\_to :action =\> :find\_id\_done  
else  
flash[:notice] = “You are NOT member.”  
end  
end  
end

* * *

[/view/login/find\_id\_done.rhtml]  
…

1. Your ID is \<%= @is\_member.uid %\>.
2. Your ID is \<%= is\_member.uid %\>
3. Your ID is \<%= is\_member[:uid] %\>

# (\* the field name of user id is “uid”.)

What is correct?

@{value\_name} is instant value ( = status of object)  
{value\_name} is normal value.  
{value\_name}[:key] is hash…

Please, Help Me!  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![mmnmm7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@mmnmm7](https://www.ruby-forum.com/u/mmnmm7)\
**Post date:** [October 18, 2007, 2:55am UTC](https://www.ruby-forum.com/t/how-get-the-value-user-id/117547/2 "2007-10-18T02:55:32Z")

</div>

Welcome to the cool club 🙂

# first, lets start with the controller.

def find\_id  
if request.post?  
@is\_member = Member.find\_by\_name\_and\_email(params[:member][:name],  
params[:member][:email])  
if @is\_member  
redirect\_to(:action =\> “find\_id\_done”, :member\_id =\> @is\_member)  
else  
flash[:notice] = “You are NOT member.”  
end  
end  
end

# def find\_id\_done @member = Member.find(params[:member\_id]) end

now for the view

Your ID is \<%= @member.id %\>.  
or if you actually have a column called uid, then  
Your ID is \<%= @member.uid %\>

just remmber that when a model is created, and the migration is ran,  
that a column called id is automatically created, so you can use that,  
unless the you want to specify an id.

~Jeremy

---

<div class="post-metadata">

**Author:** ![mmnmm7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@mmnmm7](https://www.ruby-forum.com/u/mmnmm7)\
**Post date:** [October 18, 2007, 3:07am UTC](https://www.ruby-forum.com/t/how-get-the-value-user-id/117547/3 "2007-10-18T03:07:02Z")

</div>

On Oct 17, 4:57 pm, mmnmm7 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> member = params[:member]
> 
> ```
> 
> * * *
> 
> What is correct?
> 
> @{value\_name} is instant value ( = status of object)  
> {value\_name} is normal value.  
> {value\_name}[:key] is hash…
> 
> Please, Help Me!  
> Thanks a lot!

Hi. I am also new, but I think I might get what’s up. So, several  
points:

1. While possible to do thing differently than Rails conventions  
expect, Rails works best if you follow convention, since it assumes  
you will. One issue may be that Rails’ assumption is that the primary  
key field of a table is called simply “id”, instead of something  
different like uid as in your example. If its not, you can do a  
migration using rename\_column to change uid to id.

2. The trick here is aligning the values from the form (those in the  
params hash) and the actual Member instance to be found (maybe) using  
the find method. In params you have not just a name and an email, but  
(if the form is defined as such) an instance of the Member object,  
even if not complete. And you can use this object to determine if its  
contents identify an actual member from the database. When found, a  
member will be returned as an object containing all of the member  
data. If you set up your form as a view of the Member class, you  
could do something like Member.find(:first, :conditions =\> “name  
= :name and email = :email”, params[:member]) when the form is  
submitted. In other words, if your form is defined as a view of a  
member (even if not all of the fields), it’s values will be stored in  
a hash that is one key , named :member, of the params hash. You can  
get at specific fields of the object from params like params[:member]  
[:name] if you need to, but rails is smart enough to say, “hey, I have  
a member object in params, let’s see if I can find a :name and :email  
field” to use for my condition. Is the form a view of Member? It  
should be if its fields are defined as \<% form\_for :member … %\>, or  
some variant of that.

For those of us who come from a strict, tight-binding, declarative  
world (Java, C#, SQL), this kind of loosey-goosey stuff can be  
maddening. There are at least 5 other ways to do the thing you want  
to do, and probably more. The trick is to figure out what “the flow”  
is, and then go with it! It’s not so hard to go with the flow, but I  
am still working on figuring out what the flow actually is (hard,  
since it’s not well documented, and in significant flux at the  
time :-). All I can say is, if you don’t have a copy of Agile Web  
Development with Rails (AWDWR), get one! It’s the only source I have  
found that describes, explains, and documents (not to mentioned  
provides a good index for) most of what is going on in Rails.

By the way, everything I have written is my potentially flawed attempt  
to translate your question into an example found in AWDWR combined  
with less than a month of actual experience. So take my words with a  
grain/pound of salt 🙂

Tom

---

<div class="post-metadata">

**Author:** ![mmnmm7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@mmnmm7](https://www.ruby-forum.com/u/mmnmm7)\
**Post date:** [October 18, 2007, 3:53am UTC](https://www.ruby-forum.com/t/how-get-the-value-user-id/117547/4 "2007-10-18T03:53:13Z")

</div>

At first, thanks a lot!!  
And I’m not good at speaking in English.  
I wish you understanding, please. 😉

I almost have programmed using PHP(not OOP).  
In my memory, concept of structured programming is very natural.  
It’s very hard for me to program with OOP languages like java, ruby…

I think The Most Important thing is the Basic concept of it.  
I’ll try to study more and more about the base knowledge about Ruby  
and RoR.

Thanks, again.  
Rucy.
