has_one_attached之后的方法不工作

发布于 2025-01-29 08:39:50 字数 1167 浏览 4 评论 0原文

我正在使用主动存储存储图像,但对特定模型不起作用,首先是一个具有工作模型的示例:

class GalleryImage < ApplicationRecord
  has_one_attached :image
end

在这种情况下,一切都很好,这是控制台输出:

2.7.0 :006 > ::GalleryImage.new.image
 => #<ActiveStorage::Attached::One:0x0000557a5b57b1f8 @name="image" ...>> 

但是,我还有另一个称为的模型appsetting像这样:

class AppSetting < ApplicationRecord
  def hola
    'hola'
  end

  has_one_attached :gimmick

  def adios
    'adios'
  end
end

并且,当我在Rails控制台中尝试它时:

2.7.0 :006 > ::AppSetting.new.hola
 => "hola" 
2.7.0 :007 > ::AppSetting.new.gimmick
Traceback (most recent call last):
        1: from (irb):7
NoMethodError (undefined method `gimmick' for #<AppSetting:0x0000560cb955b470>)
2.7.0 :008 > ::AppSetting.new.adios
Traceback (most recent call last):
        2: from (irb):7
        1: from (irb):8:in `rescue in irb_binding'
NoMethodError (undefined method `adios' for #<AppSetting:0x0000560cb94241d8>)

如您所见,第一个方法(hola)效果很好,但是我得到了nomethoderror( 的方法...对下一个方法的错误消息。

未定义

I am using Active Storage to store images but and doesn't work for a specific model, first an example with a working model:

class GalleryImage < ApplicationRecord
  has_one_attached :image
end

In this case everything works well, here is the console output:

2.7.0 :006 > ::GalleryImage.new.image
 => #<ActiveStorage::Attached::One:0x0000557a5b57b1f8 @name="image" ...>> 

But, I have another model called AppSetting like this:

class AppSetting < ApplicationRecord
  def hola
    'hola'
  end

  has_one_attached :gimmick

  def adios
    'adios'
  end
end

And, when I try it in the rails console:

2.7.0 :006 > ::AppSetting.new.hola
 => "hola" 
2.7.0 :007 > ::AppSetting.new.gimmick
Traceback (most recent call last):
        1: from (irb):7
NoMethodError (undefined method `gimmick' for #<AppSetting:0x0000560cb955b470>)
2.7.0 :008 > ::AppSetting.new.adios
Traceback (most recent call last):
        2: from (irb):7
        1: from (irb):8:in `rescue in irb_binding'
NoMethodError (undefined method `adios' for #<AppSetting:0x0000560cb94241d8>)

As you can see, the first method (hola) works well, but I'm getting NoMethodError (undefined method... error message for the next methods.

any help? please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文