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

Yu (Dilys) Sun
Yu (Dilys) Sun
5,812 Points

Paperclip installation missing demo videos?

Installing Paperclip Programming Advanced Social Features in Ruby on Rails Uploading Files Installing Paperclip

Watching this section, looks like the video only covers imagemagik, homebrew, and setting up seed database but nothing on the actually installation of Paperclip or the migration instructions.

Help :)

8 Answers

Have you looked at the Paperclip documentation?

Dropping the gem into your Gemfile and your usual bundle install is all that's really necessary for "installation". After that it's just...

rails g paperclip (your model) photo
rake db:migrate

Otherwise check out the railscast on paperclip. It's not going to necessarily illustrate how Paperclip works within an environment like Treebook, but it will help with understanding the general mechanics of the gem.

Hope that helps!

Yu (Dilys) Sun
Yu (Dilys) Sun
5,812 Points

That's very helpful thank you. I didn't know there's a RailsCast on it. I want to take a look before asking further question.

But yeah I reviewed the Documentation, the part hard for me to understand is how to modify the migration file to include all the important attributes.

It seems that has_attached_file needs to be in my models that have attachments like User has a profile picture, or each notepage is associated with an attached file. But it also need a migration to add add_attachment column? I am a bit confused about what to include or not in the migration files. Hopefully after the video it become clear.

Thanks fort he fast response!

I used paperclip for adding photos to Users in my web app before Treehouse expanded the Treebook project and my migration looked just like this:

class AddAttachmentPhotoToUsers < ActiveRecord::Migration
 def self.up
change_table :users do |t|
  t.attachment :photo
 end
end

def self.down
 drop_attached_file :users, :photo
 end
end

What "important attributes" are you mentioning? Using the standard migration should create photo_file_name, photo_content_type, photo_file_size, and photo_updated_at columns, while I believe any processing done with Imagemagick should result in a newly created image.

Will Lam
Will Lam
7,027 Points

Hi Dilys!

I remember seeing you on the Crunchies representing Codecademy! Cool to have you here as part of the Treehouse community too!

Followed you on Twitter :)

Cheers,

Will Lam

accidentally posted this comment, please delete

Yu (Dilys) Sun
Yu (Dilys) Sun
5,812 Points

Lol accidentally posted with my friend's account - Dilys

@zander thanks so much for the follow up. I was finally able to get the PaperClip to work. Looks like there's indeed some missing info on the Treehouse tutorial but Ryan Bates' helped a lot, as always. Just worry that beginners won't be able to pick it up (I didn't used to be able to understand Ryan's tutorials, which were more advanced).

Here's my modification to an existing model rb file:

has_attached_file :avatar

Here's my migration file to an existing model:

class AddAttachmentAvatarToTasks < ActiveRecord::Migration
  def self.up
    change_table :tasks do |t|
      t.attachment :avatar
    end
  end

  def self.down
    drop_attached_file :tasks, :avatar
  end 
end

It can also be generated with a single command after installation of PaperClip which is awesome: rails generate paperclip task avatar

@Will That's awesome :) you spotted me in the jungle ;-) I have been keeping myself very busy after Crunchies : simultaneously juggling a web development bootcamp, Codecademy and multiple online/in-person learning platforms! It's been a real stretch of imagination. How are you? I see that you are learning Rails?

Will Lam
Will Lam
7,027 Points

@Dilys - that's awesome - which web dev bootcamp? Dev Bootcamp?

It's tough as I haven't done anything from scratch yet.. I enjoy the fact that Treehouse is very approachable through their quirky humour. Might consider checking out a web dev bootcamp here in Toronto... http://www.bitmakerlabs.com

I'm getting used to the entire rails framework, but I'm itching to go off and build my own stuff. Would love to chat with you about your experience so far in terms of learning to become technical, perhaps interview you on my blog? :)

Yu (Dilys) Sun
Yu (Dilys) Sun
5,812 Points

That's totally fun and awesome. Let's chat on your blog or mine http://codesum.blogspot.com so we don't go too long with TreeHouse's actual problem solving forum ;-) yeah but I am totally happy to chat more~

I added you on my Google Plus :)