has_one_attached之后的方法不工作
我正在使用主动存储存储图像,但对特定模型不起作用,首先是一个具有工作模型的示例:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论