I am trying to return all groups created by a user. All of the groups are associated with the user id. When I run a find_by query it only returns the first result. Is there a way for it to return multiple? Thanks in advance
I'm writing a separate answer because I can't comment on James Lowrey's answer as I don't have 50 points.
find_all_by is deprecated (Ruby 4.2).
To get a list of active records from models, do:
Model.where(attribute_name: val)
For example, to find all records in Vehicle table (having column name "model_name") such that the value of model_name is "Audi", do
@vehicles = Vehicle.where(model_name: "Audi")
You can iterate through these like so:
<% @vehicles.each do |vehicle| %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With