Have a look at rails scope. I’m pretty sure this is the functionality you are looking for. http://guides.rubyonrails.org/active_record_querying.html#scopes <http://guides.rubyonrails.org/active_record_querying.html#scopes>
Basically, you define your association, then define a scope to retrieve the records how you’d like to. > On May 18, 2016, at 9:06 AM, Gm <[email protected]> wrote: > > Hi, > I'm trying to create this method: > > has_many :cars do > Car.where(color: 'red').all > end > > I'm using a class without Activerecord and outside rails: > > module API > class User < Base > include ActiveRecord::Associations > > has_many :cars do > Car.where(color: 'red').all > end > end > end > > When I run: > > undefined method `dangerous_attribute_method?' > > > How can I use a has_many and create my own implementation ? > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/769dfcb2-2d79-4bed-8d44-be354e0953ce%40googlegroups.com > > <https://groups.google.com/d/msgid/rubyonrails-talk/769dfcb2-2d79-4bed-8d44-be354e0953ce%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/39C0380E-DCD7-4719-9D4E-44C0D5D93237%40gmail.com. For more options, visit https://groups.google.com/d/optout.

