提问人:nitish 提问时间:10/26/2023 最后编辑:nitish 更新时间:10/27/2023 访问量:42
rails 7 中的 ActiveRecord::InverseOfAssociationNotFoundError
ActiveRecord::InverseOfAssociationNotFoundError in rails 7
问:
嗨,当我要打开个人资料页面时,在我的 rails 应用程序中出现以下错误 我的 ruby 版本是“3.2.2”,我的 rails 版本是“7.0.8”
ActiveRecord::InverseOfAssociationNotFoundError in Users#show
显示 /home/nitish/Documents/Bestristey/app/views/users/_user_profile_image.html.erb,其中第 #3 行升起:
ActionView::Template::Error(找不到 profile_image_attachment 的反向关联(ActiveStorage::Attachment 中的 :record)):
1: <div id="profile_image">
2: <div>
3: <% if user.profile_image.attached? %>
4: <%= image_tag(user.profile_image, class: "d-block ui-w-80 " ) %>
5: <% else %>
6: <img src ="/assets/dummy profile.jpg" alt class="d-block ui-w-80 rounded-circle">
这是我的用户模型的代码:-
class User < ApplicationRecord
after_create :after_confirmation
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable,
:confirmable, :trackable
validates :username, presence: true, uniqueness: true
has_one_attached :profile_image
attr_accessor :login
def login
@login || self.username || self.email
end
end
这是我的models/active_storage/attachment.rb文件中的代码:-
`
class ActiveStorage::Attachment < ApplicationRecord
belongs_to :blob, class_name: "ActiveStorage::Blob"
def self.ransackable_attributes(auth_object = nil)
["blob_id", "created_at", "id", "name", "record_id", "record_type"]
end
end
我尝试在用户模型has_one_attached关联中使用 :inverse_of,但随后它给出了参数错误。我也尝试了一些其他的东西,但仍然没有任何进展。
答: 暂无答案
评论