문제 Url 을 가진 썸네일을 사용하여 만든 신사 플러그인을 레일에 6

0

질문

나는 어려움을 겪고되었을 이해의 몇 가지 일하고 바라고 누군가가 도움이 될 수 있습니다. 무언가가있을 수 있다는 명백한 목표를 설정했습니다.!

내가 사용하고사 플러그인에 대한 레일을 업로드하는 PDF 파일 생성하기 위한 첫 번째 페이지로 이동합니다. PDF 드에서 지정한 저장 공간 축소판이 만들어지고 점점에서 정렬은 같은 위치에 있습니다. 그러나 나는 할 수 없 표시 썸네일에는 뷰입니다.

이니셜라이저:

require "shrine"
require "shrine/storage/file_system"
#require "shrine/storage/memory"

Shrine.storages = {
    cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"),
    store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store")
}

Shrine.plugin :activerecord    # loads Active Record integration
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
Shrine.plugin :restore_cached_data  # extracts metadata for assigned cached files
Shrine.plugin :determine_mime_type
Shrine.plugin :validation_helpers
Shrine.plugin :validation
Shrine.plugin :derivatives
#Shrine.plugin :model, cache: false

Uploader:

require "image_processing/mini_magick"

class FileUploader < Shrine
 include ImageProcessing::MiniMagick

 plugin :processing # allows hooking into promoting
 plugin :versions   # enable Shrine to handle a hash of files
 plugin :derivatives
 plugin :default_url
# plugin :delete_raw # delete processed files after uploading

 Attacher.validate do
  validate_max_size 5*1024*1024, message: "is too large (max is 5 MB)"
  validate_mime_type %w[application/pdf]
 end

 Attacher.derivatives do |original|
  magick = ImageProcessing::MiniMagick.source(original).loader(page:0).convert("jpeg")
  {
   thumb: magick.resize_to_limit!(200, 200) 
  }

 end

end

테스트보기:

<p id="notice"><%= notice %></p>

<p>
  <strong>Number:</strong>
  <%= @issue.number %>
</p>

<p>
  <strong>Title:</strong>
  <%= @issue.title %>
</p>

<p>
  <strong>Data:</strong>
  <%= @issue.file_data %>
</p>

<p>
  <strong>Issue Preview</strong>
  <embed src="<%= @issue.file_url %>" width="80" height="160" />
</p>

<p>
  <strong>Issue Thumbnail:</strong>
  <%= image_tag @issue.file_url(:thumb) if @issue.file %>
</p>

<p>
  <strong>Issue:</strong>
  <%= image_tag @issue.file_url if @issue.file %>
</p>

<%= link_to 'Edit', edit_issue_path(@issue) %> |
<%= link_to 'Back', issues_path %>

또한,볼 때에 저장된 데이터 file_data 분야 전혀 보이지 않는 정보를 추가합니다.

파일 데이터:{"id":"fccd20a9323aa5b63fd912f4ca833ebb.pdf","storage":"store","metadata":{"filename":"pdf_sample.pdf","size":351987,"mime_type":"application/pdf"}}

pdf ruby-on-rails shrine thumbnails
2021-11-20 21:41:41
2
0

당신이 필요하도록 설정하려면 다음 중 하나를 자동 생성에 첨부 홍보 영구적인 저장소:

Shrine.plugin :derivatives, create_on_promote: true

또는 프로세스는 파생상품에서 수동으로 첨부:

record.file_derivatives!
2021-11-21 19:40:25

주셔서 감사합니다 당신을 당신의 빠른 응답을 할 수 있습니다. 가 처리하는 파생 상품 모두 방법으로 당신은 위의 제안과 축소판이 만들어지고 sored 와 함께 첨부된 pdf 파일이 없는 문제입니다. 내 호출할 수도 있습니스의 URL 을 파일에서 내보기를 통해@문제입니다.file_url. 는 유일한 것은 나를 위해 일하는 URL 을 축소판@문제입니다.file_url(:엄지손가락). 에 대한 데이터를 축소판한 저장하지 않습에서 file_data 란:{"id":"a94c1a6e31176ed530b786ef3cefe18a.pdf","storage":"store","metadata":{"filename":"comic_sample.pdf","size":351987,"mime_type":"application/pdf"}}.
user1851592

물에서 누락된 데이터 열을 의미하는 파생지 생성하고,그 이유는 URL 은 전무합니다. 기 때문에 당신이 게시하지 않고 설치 create_on_promote: true 설정,그리고 당신은 표시되지 않은 파생물을 만드는 명시적으로 나가는 것을 가정 그것은 단순히지 않았 라고 합니다.
janko-m

다시 한번 감사,ill have a look at my 설정을 다시합니다. 빠른 질문은 어떻게 축소판을 얻을 생성하는 경우 부착기.파생상품은 없습니까?
user1851592
0

마지막으로 그것을 알아 냈다. 내가 문제를 해결을 추가하여 다음을 _form.html.erb:

<%= form.hidden_field :image, value: @photo.cached_image_data %>
2021-12-08 23:46:19

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................