无法将头像附加到Rails 6 usgin ActiveStorage中的模型

时间:2019-06-08 02:52:52

标签: ruby-on-rails rails-activestorage

我正在尝试将头像附加到个人资料模型。我有rails 5.2应用程序,并更新为rails6。这是上传头像的表格。

enter image description here

在配置中,我需要活动存储引擎 require_relative'启动'

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 :(得分:0)

我在生产中有以下产品,但没有开发中的产品,这就是造成此问题的原因。

config.active_storage.service = :local