1

想用神社gem,看了一个神社图片裁剪神社上传端点插件,然后参考示例代码,首先我复制了示例代码,但是发生了

 ActionController::RoutingError (No route matches [GET] " 
/uploads/cache/47eee6dc368f20db1e26fa5176552136.jpg"):

我认为这个错误我无法发送正确的路径,我没有解决这个错误,即我没有很好地使用 Upload Endpoint 插件,我可以发送 Post 请求但无法使用 get 请求

有人教我如何在神社中使用get request,好吗?

form.html.erb:

<div class ="container">
 <div class ="row">
 <%= form_with model: @photo, url:   photos_new_path,local: true do |f| %>

  <div class="form-group">

  <%= f.label :image %>

  <%= f.hidden_field :image, value: @photo.cached_image_data, class: "upload-data" %>

  <%= f.file_field :image, accept: ImageUploader::ALLOWED_TYPES.join(","),
 data: {
  upload_server: "upload_server",
  preview_element: "preview-photo",
  upload_result_element: "preview-photo-upload-result",
 }%>

  <div class="image-preview">
  <!-- static link to the thumbnail generated on attachment -->
  <%= image_tag @photo.image_url.to_s,
  width: 300,
  class: "img-thumbnail file-upload-preview",
  id: "preview-photo" %>
 </div>

 </div>

 <%= f.submit "create", class: "btn btn-primary" %>

<% end %>
</div>

路线.rb:

 Rails.application.routes.draw do

 get 'photos/new'
 mount ImageUploader.upload_endpoint(:cache) => "/app/assets/images/uploads"
 mount ImageUploader.derivation_endpoint => "/derivations/image"
 mount ImageUploader.presign_endpoint(:cache) => "/images/presign"


 get 'sessions/new'

 devise_for :users

 resources :users do
  resources :photos 

 end
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end

Shrine.rb 插件:

require "shrine"
require "shrine/storage/file_system"




Shrine.storages = {
 cache: Shrine::Storage::FileSystem.new("app/assets/images", prefix: "uploads/cache"), # temporary
 store: Shrine::Storage::FileSystem.new("app/assets/images", prefix: "uploads"),       # permanent
}


Shrine.plugin :pretty_location
Shrine.plugin :determine_mime_type, analyzer: :marcel


Shrine.plugin :activerecord           # loads Active Record integration
Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays
Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file

Shrine.plugin :validation_helpers


Shrine.plugin :derivatives
Shrine.plugin :derivation_endpoint, secret_key: "secret", expires_in: 10

Shrine.plugin :upload_endpoint, url: true
Shrine.plugin :default_url


 Shrine.plugin :backgrounding

Image_uploader.rb 的插件:

plugin :store_dimensions, analyzer: :ruby_vips, log_subscriber: nil
plugin :derivatives

plugin :derivation_endpoint, prefix: "derivations/image"
plugin :presign_endpoint

我用 console.log 检查了路径,所以 response.uploadURL 是

/uploads/cache/47eee6dc368f20db1e26fa5176552136.jpg
4

0 回答 0