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.
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?
ty!!
If the name is unique, you could do something like this:
Hey
All the columns in your database/model have ‘finder’ attributes,
thanks to ActiveRecord and inheritance, which means you can do either;
a=Booking.find_by_confirmation_date("2005-06-06 00:00:00")
or even
a=Booking.find_all_by_confirmation_date("2005-06-06 00:00:00")
I hope you get the idea ;) Note, if your name is not 'unqiue', then
obviously, doing the find_by will return the first name that matches,
which in the database could be random. Your mileage will definitely
vary.
Regards
Stef
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.