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

Malachai Frazier
Malachai Frazier
7,352 Points

S3 Paperclip mp3 url issues in Rails 3?

Here is my Track Model: has_attached_file :audio, :storage => :s3, :s3_credentials => "#{Rails.root}/config/environments/s3.yml", :path => "/user_:profile_name/:class/:attachment/:basename.:extension", :bucket => "Butter"

Le gems; gem "paperclip", "~> 3.4.0" gem "aws-sdk", '~> 1.3.4'

I'm seeing some oddness when trying to retrieve the URL for a (successfully) uploaded track... In Amazon I can see the URL here; https://s3.amazonaws.com/Butter/user_Admin/tracks/audios/1watch_this.mp3 But when I call the audio tag in my view I see this oddness; /audios/original/missing.png?1356837927

Help?

6 Answers

Steve Monsen
Steve Monsen
5,207 Points

I'm no rails expert, but is there a slash missing here?

Original: :path => "/user:profile_name/:class/:attachment/:basename.:extension"

Should possibly be: :path => "/user*/*:profile_name/:class/:attachment/:basename.:extension"

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

I believe you will also need to specify the :url has key for this to work correctly in the view:

has_attached_file :audio, 
  path: "/user/:profile_name/:class/:attachment/:basename.:extension",
  url: "http://s3.amazonaws.com/Butter/user/:profile_name/:class/:attachment/:basename.:extension"

Try checking out the rdoc for more info: http://rdoc.info/gems/paperclip/Paperclip/ClassMethods:has_attached_file

Malachai Frazier
Malachai Frazier
7,352 Points

Good catch Steve Monsen, lil typo on my part. Still broken, though...

Malachai Frazier
Malachai Frazier
7,352 Points

Thanks Jaskn Seifer! I'll try that as soon as I can get back to my box

@Malachai keep us in the loop if it works :D

Malachai Frazier
Malachai Frazier
7,352 Points

I ended up going with this setup here:

has_attached_file :audio,
storage: :s3,
s3_credentials: "#{Rails.root}/config/environments/s3.yml",
path: "/user/:profile_name/:class/:attachment/:id_partition/:basename.:extension",
url: "https://s3.amazonaws.com/Butter/user/:profile_name/:class/:attachment/:id_partit    ion/

:basename.:extension",
bucket: "Butter"

Then I had to dump and rebuild the entire database (for whatever reason). Don't forget to run

heroku restart

After all of that, she works! Thanks guys!!