I
I
IvanN7772014-11-08 14:30:18
Ruby on Rails
IvanN777, 2014-11-08 14:30:18

Paperclip medhod url not working, what to do?

There is a desire to store pictures in Paperclip
1) Installed gem gem 'paperclip'
2) Added migration

class AddFileColumnsToLinksFilesMaterials < ActiveRecord::Migration
  def change
    def self.up
      add_attachment :links_files_materials, :file_material
    end

    def self.down
      drop_attached_file :links_files_materials, :file_material
    end
  end
end

3) Registered in the model
class LinksFilesMaterials < ActiveRecord::Base
  belongs_to :project_material

  enum type_file: {cutting: 0, design: 1 }

  has_attached_file :file_material
  do_not_validate_attachment_file_type :file_material

  attr_accessor :file_material_file_name
  attr_accessor :file_material_content_type
  attr_accessor :file_material_file_size
  attr_accessor :file_material_updated_at
end

4) saved
@links_files_m=LinksFilesMaterials.create(project_material_id: material_id, type_file: LinksFilesMaterials.type_files[:cutting],file_material:params_arr[:file1])

5) It was saved and recorded, but this is where the problem arose
6) In the create method itself
@links_files_m.file_material.url
It seems to be a normal path
I call the same object (with the same id) then in other controllers
Writes: /file_materials/original/missing.png
There are files on the server , where is the mistake?????????? pliz
I watched the guide in that chile habrahabr.ru/sandbox/40855

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Skuridin, 2014-11-09
@skuridin

Write the path in the model with pens, otherwise it looks like it is looking from the root of the server, where this file does not exist.

{
  url: '/uploads/:class/:id/:style.:extension',
  path: ':rails_root/public:url'
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question