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 Build a Simple Ruby on Rails Application Building the Profile Page Scoping

Marc Burt
Marc Burt
9,828 Points

DEPRECATION WARNING: Relation#all is deprecated.

Hi,

I followed this video and my code works, but I get a warning when running the test, I'm guessing since I'm using a newer version of rails. The warning is 'DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. Post.where(published: true).load). If you want to get an array of records from a relation, you can call #to_a (e.g. Post.where(published: true).to_a). (called from show at d:/Ruby Work/Treebook/treebook/app/controllers/profiles_controller.rb:6)'

I thought I'd try the new method suggested, but can't get that correct.. My best guess at following the warning is:

Statuses.where(user: @user).to_a

What have I got wrong?

Andrew Rice
Andrew Rice
2,233 Points

I just figured this out myself and figured I wouldn't leave this question unanswered.

The correct code seems to be:

@statuses = @user.statuses.to_a

It still works as expected and the test passes, plus no deprecation warning.

3 Answers

Andrew Rice
Andrew Rice
2,233 Points

Whoops... posted as a comment instead of an answer. Not used to this...

Here is the post as an answer:

I just figured this out myself and figured I wouldn't leave this question unanswered.

The correct code seems to be:

@statuses = @user.statuses.to_a

It still works as expected and the test passes, plus no deprecation warning.

instead of using the new methodology, trying going back to hash rockets (=>) or use rvm to install different versions of ruby

Marc Burt
Marc Burt
9,828 Points

Sorry if it isn't clear in the questions JoJo,

I have my code working as it was explained in the video, I just can't understand the new methodology and was hoping someone could explain it.

Doug Tucker
Doug Tucker
7,437 Points

I tried @statuses = @user.statuses.load and that seemed to work from Scoping video in Track 8 in building a simple rails app

Marc Burt
Marc Burt
9,828 Points

Hi Doug,

Yes, this is the video I asked the question for - as mentioned in the question it also worked for me. The warning doesn't stop it working, just mentions the method is depreciated, which I think means it'll be phased out. I'm looking for an answer on the new method it suggests.