Does paperclip work in development but not in production?

I am new to rails and there seems to be a problem with a paper clip. I installed the gem and it works well in development (localhost: 3000), but when I run it on the heroku server, for some reason it does not want to attach files, and the application crashes (page with 500 error).

Here is the process that I started ... I pushed my file to the hero, heroku launched rake db: migrate (to add paperclip migrations), and then I restarted the hero (to restart the application with new migrations). It did not help.

Here is the code I have for the clip:

user.rb model:

has_attached_file :avatar, :styles => {:small => "70x70>"}, :url => "/users/:attachment/:id/:style/:basename.:extension", :path => ":rails_root/public/users/:attachment/:id/:style/:basename.:extension" validates_attachment_size :avatar, :less_than => 500.kilobytes validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png'] 

edit_form.html.haml view:

  = form_for (@user || User.new), :html => { :multipart => true } do |f| ... .profile_picture.text_field = image_tag current_profile.avatar.url(:small) %br = f.file_field :avatar 

Again, for some reason, it develops well in development, but breaks down in production. Any pointers would be greatly appreciated ... I just can't figure it out, and it's pretty unpleasant. Thank you so much for your time and any help!

+6
source share
2 answers

In your model.

 has_attached_file :picture, :styles => {:large => "275x450>"}, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "appname/:attachment/:style/:id.:extension" 

In s3.yml in your config directory:

  development: bucket: bucketname access_key_id: key secret_access_key: key production: bucket: bucketname access_key_id: key secret_access_key: key 

Then go to the registration for the bucket in Amazon S3: http://aws.amazon.com/s3/

+3
source

You may have several problems. However, firstly, you cannot write to the file system on Heroku. You will have to implement another storage engine such as s3. You can read about this limitation here: http://devcenter.heroku.com/articles/read-only-filesystem

+1
source

Source: https://habr.com/ru/post/895291/


All Articles