试图在 Rails 关注中获取包含 class 的名称
trying to get name of enclosing class in a Rails concern
第一次使用问题,只是寻求一些建议。
我有一个名为 location.rb 的 Rails 模型,我想包含一个 AlbumDefineConcern,然后查询我们当前所在的模型 class(在这个 class 位置).
我有:
class Location < ActiveRecord::Base
include AlbumDefineConcern
...
和
module AlbumDefineConcern
extend ActiveSupport::Concern
albums={}
albums_locations = ["LocationHomeFeed","LocationProfile","LocationMobileMain"]
albums[:locations]=albums_locations
# I'd like it to output location or Location
puts "here is class_name #{self.name}"
如何获得 "location" 作为 class 名称?
# puts "here is class_name #{self.parent.name}" => Object
module AlbumDefineConcern
extend ActiveSupport::Concern
included do
puts self
end
end
第一次使用问题,只是寻求一些建议。
我有一个名为 location.rb 的 Rails 模型,我想包含一个 AlbumDefineConcern,然后查询我们当前所在的模型 class(在这个 class 位置).
我有:
class Location < ActiveRecord::Base
include AlbumDefineConcern
...
和
module AlbumDefineConcern
extend ActiveSupport::Concern
albums={}
albums_locations = ["LocationHomeFeed","LocationProfile","LocationMobileMain"]
albums[:locations]=albums_locations
# I'd like it to output location or Location
puts "here is class_name #{self.name}"
如何获得 "location" 作为 class 名称?
# puts "here is class_name #{self.parent.name}" => Object
module AlbumDefineConcern
extend ActiveSupport::Concern
included do
puts self
end
end