You should be able to use find_by and pass in a hash with attributes and respective values to find a record.
Please take a look at the docs for find_by on the api guides. Carlos Antonio da Silva - via celular On Nov 14, 2014 7:44 PM, "Sunny Juneja" <jr.su...@gmail.com> wrote: > Hey, I ran into this problem fairly recently. I needed to get a large > number of records and search them over and over again on different > attributes. I found myself writing code that looked a lot like this. > > records = Model.where(...) > > records.select { |r| r.attribute1 == attribute1 && r.attribute2 == > attribute2 && ... } > > Although this is a simple case, I found myself rewriting this over and > over again. > > Is there anything equivalent that might fit the form > > records = Model.where(...) > records.find_in_relation(attribute1: attribute1, attribute2: attribute2, > attribute3, ...) > > Was just wondering if there was a place for such syntactical sugar or a > desire to add some. If there is too simple a change to warrant, I > understand. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.