Paperclip을 사용하여 파일이 첨부 된 두 개의 모델이 있습니다. 이 두 모델은 거의 동일하지만 두 번째 모델의 각 클래스에서 'attachment_name '메서드를 호출하면 nil이 반환됩니다.Paperclip attachment_name은 nil을 반환합니다.
중요한 정보가 무엇인지 알지 못해 두 모델의 코드가 게시되지 않았습니다. 레일 콘솔에서 내가 두 번째 모델 두 모델에 대한 첨부 파일 이름을 얻으려고 그래서
class JobExtra < ActiveRecord::Base
belongs_to :job
has_attached_file :file
validates_attachment :file, content_type: { content_type: [/\Aimage\/.*\Z/, 'application/pdf'] },
size: { in: 0.megabytes..5.megabytes }
end
: 여기
class DocumentationFile < ActiveRecord::Base
belongs_to :documentation
has_attached_file :file, styles: { large: '720x720>', medium: '300x300>', thumb: '100x100>' },
default_url: '/images/:style/missing.png'
validates_attachment :file, content_type: { content_type: [/\Aimage\/.*\Z/, 'application/pdf'] },
size: { in: 0.megabytes..5.megabytes }
validates :file, presence: true
end
이 두 번째입니다 : 여기
첫 번째 모델이다 나는 아무 일도 일어나지 않고있다.
2.3.3 :003 > DocumentationFile.attachment_name
=> :file
2.3.3 :004 > JobExtra.attachment_name
=> nil
내가 왜 그런 일이 일어나고 있는지 잘못 이해하고있다. has_attached_file
에 동일한 유효성 검사와 옵션을 추가하려고했지만 도움이되지 않았습니다.
그래서 아이디어가 없어졌고이 문제로 인해 내 정신이 차질났습니다. 어떤 도움을 주셔서 감사합니다!