首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用ActiveStorage将头像附加到Rails 6中的模型

无法使用ActiveStorage将头像附加到Rails 6中的模型
EN

Stack Overflow用户
提问于 2019-06-08 10:52:52
回答 1查看 1.4K关注 0票数 0

我在试着把一个头像附加到一个侧面模型上。我有rails 5.2应用程序,并更新到rails 6。这是上传头像的表单。

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

代码语言:javascript
复制
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。

代码语言:javascript
复制
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 

如何将图像附加到配置文件头像?

EN

回答 1

Stack Overflow用户

发布于 2019-06-08 21:34:37

我在生产中有以下内容,但在开发中没有,这是导致问题的原因。

config.active_storage.service = :local

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56503045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档