Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!!