I have this loop:
stations = Station.where(...) stations.all.each do |s| if s.city_id == city.id show_stations << s end end This works well, but because of looping the all the data, I think it's kinda slow. I've tried to rewrite it with using select, like this:
show_stations << stations.select { |station| station.city_id == city.id} But the amount of saved data into show_stations is different compared to the each version and then, the data are in different format (array/object).
Is there any better/faster way to rewrite the loop version?
citycome from? The more logic you can put into thewhereclause, the faster the code will be because the returned dataset will be smaller.