how can i find an ID from a table, with another attribute? i mean, i
have the table users, with id, and name, and i want to find the id,
where the name is.
i know only the way with the id…
@something = User.find(params[:id])
which would be the correct syntax?
If the name is unique, you could do something like this:
@id = Users.find_by_name(@name).id
@id = Users.find(:first, :conditions => [ “name = ?”, @name]).id
These will only find the first matching record though, so if you have
duplicate names you’ll have to take only a slightly different route.
(apologies if there’s a slight error or two in the code as it’s late and
i’m a bit tired, but the general idea is there)