具有rails的模块的类名和子类名之间的冲突名称

时间:2016-02-12 14:42:28

标签: ruby-on-rails ruby-on-rails-4 module namespaces

我在模型中有Effect个类,在"effect"类中有app/models/effect/个文件夹,如Effect::Status。在此配置中,效果类与带有轨道的模块类似。

但我在模特中有另一个班级Status

class Status < ActiveRecord::Base

  DEATH = 1

现在我想在Effect类中调用此常量,例如:

class Effect
  def self.apply
    foo = Status::DEATH
  end
end

但是,我有以下错误:

  

未初始化的常量效果::状态::死亡

我认为StatusEffect::Status

之间存在冲突

那我怎么解决这个问题呢?

1 个答案:

答案 0 :(得分:1)

首先要求class ImageButton(Gtk.EventBox): def __init__(self): super(Gtk.EventBox, self).__init__() # Load the images for the button self.button_image = Gtk.Image.new_from_icon_name("edit-delete", Gtk.IconSize.MENU) self.button_pressed_image = Gtk.Image.new_from_icon_name("edit-delete-symbolic", Gtk.IconSize.MENU) # Add the default image to the event box self.add(self.button_image) # Connect the signal listeners self.connect('realize', self.on_realize) self.connect('button-press-event', self.on_button_pressed) self.connect('button-release-event', self.on_button_released) def update_image(self, image_widget): self.remove(self.get_child()) self.add(image_widget) self.button_pressed_image.show() def on_realize(self, widget): hand_pointer = Gdk.Cursor(Gdk.CursorType.HAND1) window = self.get_window() window.set_cursor(hand_pointer) def on_button_pressed(self, widget, event): self.update_image(self.button_pressed_image) def on_button_released(self, widget, event): self.update_image(self.button_image) 班级加入Status

然后,使用前面的Effect访问它,表示没有父模块。

::