Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Rails 3 conditions translated to Rails 4.

Having trouble with the syntax on the has_many conditions

Rails 3 -

has_many :friends, through: :user_friendships,
                     conditions: { user_friendships: { state: 'accepted'} }

I've tried every variation I can think of to update the deprecated conditions syntax.

Can anyone help?

3 Answers

This is a shot in the dark, but give it a try

has_many :friends, -> { where(user_friendships: { state: 'accepted' }) }, through: :user_friendships

?

Perfect, it worked Nicholas, thanks so much! I had tried that code before, but I either made a syntax error, or putting the through: at the end worked.

Thanks again!

Absolutely! :)