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

[Paperclip]Store attached files from status into image gallery

hey guys. i was following the tutorial on how to build treebook and attach files to statuses. My question now. Everything is working but I want to store the attached data from the statuses right into a users gallery. like the "Timeline Photos" folder at facebook. Any ideas how to fix this with just some lines of code? maybe some kind of album.picture = self.attachment.url -> save. Is this possible?

greetz and happy new year :)

5 Answers

You can just create an automatic album that exists for all users called "Status Attachments" or whatever you want to call that.

Then you want to run a specific query. Something like:

@status_attachments = @user.statuses.where('document_id IS NOT NULL')

That will look for all statuses that have an ID in the document_id column. Then, you can look through each of those and display the actual picture like it was an album.

Kelvin - Anything is possible! I'm not sure if this is what you had in mind? Here is a link Bootstrap Images that may help you, or not? You may also gain ideas from the examples of websites found on bootstrap as well.

Hey. Thanks for the answer. I am currently using bootstrap as the UI and thats not the problem. It is the backend. I have currently 3 Models. One for attached status files, one for albums and one for pictures in that albums. I want to kinda merge this pictures and attached file model so the attached status files were directly stored into an album and not just visible by looking at the statuses any ideas? Or maybe just say the attached files should also be shown in a folder at the albums index page?

Yesss. That really much sounds like a solution :) Thank you. Just another question. How to create an automatic album? :P

Well in the view for you albums, should be the code:

albums.each do |album|

end

This loops through all the albums for that user in the database. Since this album will always exist, we should just put it before these albums. Something like:

<%= link_to( put a link to this specific album ) %>

Then, in your routes file, make a route that goes to that specific album. You will also need to add a new action for that in your pictures controller.

I don't want to do the code for you, because part of learning is to try and see if you can do it on your own. If you get stuck, post your code here and I can help you further.

Good luck!