无法将图片解析为URL:to_model委托给附件,但是附件为空

时间:2019-06-07 04:00:32

标签: ruby-on-rails ruby rails-activestorage

我正在尝试将avatar附加到个人资料。但是,出现以下错误。enter image description here

我从Rails 5.2升级到Rails6。我遍历了活动存储的配置。我的个人资料模型中有以下内容。

class Profile < ApplicationRecord
  belongs_to :user
  has_one_attached :avatar
end

这是控制者

class ProfilesController < ApplicationController
  def new
    @profile = current_user.build_profile
  end

  def create
    @profile = current_user.create_profile(profile_params)
    @profile.avatar.attach(params[:profile][:avatar])
  end

  def show
    @profile = current_user.profile
  end


 def profile_params
    params.require(:profile).permit(:full_name, :city, :bio, :avatar)
  end


2.5.0 :003 > profile = profile[0]
  Profile Load (0.4ms)  SELECT "profiles".* FROM "profiles"
 => #<Profile id: 1, user_id: 1, full_name: "steven", city: "New York", bio: "Whats goodie G", created_at: "2019-06-07 02:27:37", updated_at: "2019-06-07 02:27:37"> 
2.5.0 :004 > profile.avatar
 => #<ActiveStorage::Attached::one:0x00007f94bf358508 @name="avatar", @record=#<Profile id: 1, user_id: 1, full_name: "steven", city: "New York", bio: "Whats goodie G", created_at: "2019-06-07 02:27:37", updated_at: "2019-06-07 02:27:37">> 
2.5.0 :005 > exit

这是模型:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  has_many :photos
  has_one :profile
  accepts_nested_attributes_for :profile
end

问题出在哪里?

0 个答案:

没有答案