Answer the question
In order to leave comments, you need to log in
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
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
@links_files_m=LinksFilesMaterials.create(project_material_id: material_id, type_file: LinksFilesMaterials.type_files[:cutting],file_material:params_arr[:file1])
@links_files_m.file_material.url
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question