Невозможно прикрепить аватар к модели в Rails 6 usgin ActiveStorage - PullRequest
0 голосов
/ 08 июня 2019

Я пытаюсь прикрепить аватар к модели профиля. У меня было приложение rails 5.2 и обновлено до rails 6. Вот форма для загрузки аватара.

enter image description here

В конфигурации мне требуется активный механизм хранения require_relative 'boot'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "active_storage/engine"

# require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module ArtsySpace
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1
    # Use Vips for processing variants.
    config.active_storage.variant_processor = :vips
    # Use ActiveStorage for file storage
    config.active_storage.service
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.
  end
end

Когда я ищу профиль avatar, я вижу его в консоли. Но когда я проверяю, подключен ли он, он возвращает false.

2.5.0 :004 > Profile.first.avatar.methods
  Profile Load (0.4ms)  SELECT "profiles".* FROM "profiles" ORDER BY "profiles"."id" ASC LIMIT $1  [["LIMIT", 1]]
 => [:detach, :blank?, :purge, :attach, :attachment, :purge_later, :attached?, :method_missing, :record, :name, :to_json, :to_param, :to_query, :deep_dup, :acts_like?, :with_options, :duplicable?, :present?, :presence, :html_safe?, :as_json, :__binding__, :pry, :in?, :presence_in, :instance_values, :instance_variable_names, :to_yaml, :pretty_print_cycle, :pretty_print_inspect, :pretty_print, :pretty_print_instance_variables, :try!, :try, :unloadable, :require_or_load, :load_dependency, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :instance_variable_get, :public_methods, :instance_variables, :pretty_inspect, :method, :public_method, :define_singleton_method, :singleton_method, :public_send, :class_eval, :extend, :to_enum, :enum_for, :gem, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :byebug, :remote_byebug, :debugger, :to_s, :display, :nil?, :hash, :class, :clone, :singleton_class, :itself, :dup, :taint, :yield_self, :untaint, :tainted?, :untrusted?, :untrust, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :!, :equal?, :instance_eval, :instance_exec, :==, :!=, :__id__, :__send__] 
2.5.0 :005 > Profile.first.avatar.attached?
  Profile Load (0.4ms)  SELECT "profiles".* FROM "profiles" ORDER BY "profiles"."id" ASC LIMIT $1  [["LIMIT", 1]]
  ActiveStorage::Attachment Load (0.5ms)  SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4  [["record_id", 1], ["record_type", "Profile"], ["name", "avatar"], ["LIMIT", 1]]
 => false 

Как я могу прикрепить изображение к аватару профиля?

1 Ответ

0 голосов
/ 08 июня 2019

У меня было следующее в производстве, но не в разработке, и это вызывало проблему.

config.active_storage.service = :local

...