第一次使用关注点,只是寻求一些建议。
我有一个名为 location.rb 的 Rails 模型,希望包含一个 AlbumDefineConcern,然后查询我们当前所在的模型类(在此类 Location 中)。
我有:
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}"
如何将“位置”作为类名?
# puts "here is class_name #{self.parent.name}" => Object
最佳答案
module AlbumDefineConcern
extend ActiveSupport::Concern
included do
puts self
end
end
关于ruby-on-rails - 尝试获取 Rails 关注点中封闭类的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31951916/