Я работаю над приложением, которое раньше отлично работало с активным хранилищем. Но я не уверен, что произошло, но он больше не работает и показывает битое изображение:
Вот что я делал в прошлом на моем модель контакта:
has_one_attached :contact_avatar
И в моем views/index.html.erb
:
<%= image_tag contact.contact_avatar.attached? ? contact.contact_avatar : "100x100.png", class: "media-object img-thumbnail img-rounded mr-3" %>
Есть идеи, что вызывает это?
ПОДРОБНЕЕ : Каждый раз Я пытаюсь вставить или загрузить фотографию с помощью ActiveStorage. У меня всегда есть это на моем терминале:
[ActiveJob] [ActiveStorage::AnalyzeJob] [875b372f-3647-4ba0-8beb-3fe38e8885d3] (9.6ms) COMMIT
[ActiveJob] [ActiveStorage::AnalyzeJob] [875b372f-3647-4ba0-8beb-3fe38e8885d3] ↳ /Users/richard/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/log_subscriber.rb:98
[ActiveJob] [ActiveStorage::AnalyzeJob] [875b372f-3647-4ba0-8beb-3fe38e8885d3] Performed ActiveStorage::AnalyzeJob (Job ID: 875b372f-3647-4ba0-8beb-3fe38e8885d3) from Async(default) in 104.68ms
Started GET "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBHQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--05a842304d7509391444fb7250f49645b77cff00/madman.png" for ::1 at 2020-05-29 13:13:19 +0800
Processing by ErrorsController#page_not_found as PNG
Parameters: {"path"=>"rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBHQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--05a842304d7509391444fb7250f49645b77cff00/madman"}
Rendering errors/404.html.erb within layouts/application
Rendered errors/404.html.erb within layouts/application (0.8ms)
Вот контроллер контактов:
class ContactsController < ApplicationController
before_action :set_contact, only: [:show, :edit, :update, :destroy]
skip_before_action :verify_authenticity_token, only: [:destroy]
before_action :authenticate_user!
def index
@contacts = current_user.contacts.order(created_at: :desc).page(params[:page])
@contacts = @contacts.where(category_id: params[:category_id]) if params[:category_id].present?
@contacts = @contacts.search(params[:term]) if params[:term].present?
end
def autocomplete
@contacts = current_user.contacts.order(created_at: :desc).page(params[:page])
@contacts = @contacts.where(category_id: params[:category_id]) if params[:category_id].present?
@contacts = @contacts.search(params[:term]) if params[:term].present?
render json: @contacts.map { |contact| { id: contact.id, value: contact.name }}
end
def show
end
def new
@contact = Contact.new
end
def edit
authorize @contact
end
def create
@contact = current_user.contacts.build(contact_params)
@success = @contact.save ? true : false
respond_to do |format|
if @success
format.html { redirect_to contacts_path, notice: 'Contact was successfully created.' }
format.js
else
format.js
end
end
end
def update
@success = @contact.update(contact_params) ? true : false
respond_to do |format|
if @success
format.html { redirect_to contacts_path, notice: 'Contact was successfully updated.' }
format.js
else
format.js
end
end
end
def destroy
authorize @contact
@contact.destroy
respond_to do |format|
format.html { redirect_to contacts_url, notice: 'Contact was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_contact
@contact = Contact.find(params[:id])
end
def contact_params
params.require(:contact).permit(:name, :email, :mobile, :phone, :country, :address, :city, :state, :zip, :note, :category_id, :contact_avatar)
end
def has_error?(resource, field)
resource.errors.messages[field].present?
end
def get_error(resource, field)
msg = resource.errors.messages[field]
field.to_s.capitalize + " " + msg.join(' and ') + '.'
end
helper_method :has_error?
helper_method :get_error
end
Вот storage.yml
файл:
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket
# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name
# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]