【问题标题】:trying to get name of enclosing class in a Rails concern试图在 Rails 关注中获取封闭类的名称
【发布时间】:2015-08-11 21:04:52
【问题描述】:

第一次使用关注点,只是在寻找一些建议。

我有一个名为 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

【问题讨论】:

    标签: ruby-on-rails activesupport-concern


    【解决方案1】:
    module AlbumDefineConcern
        extend ActiveSupport::Concern
    
        included do
            puts self
        end
    
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 2022-07-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 1970-01-01
      相关资源
      最近更新 更多