title: How can I share data with a concern in Rails 4.2?
body: <p>I am attempting to use Rails Concerns (or even a bare Module mixin) to share methods across some of my models.</p>
  
  <p>Given a simple model, I am storing some encoded data in one of the 
  fields:</p>
  
  <pre><code>class DataElement &lt; ActiveRecord::Base
      include EmbeddedData
  
      ENCODED = %w(aliases)
  end
  </code></pre>
  
  <p>I’ve then made a concern with the needed methods for managing the data:</p>
  
  <pre><code>module EmbeddedData
      extend ActiveSupport::Concern
  
      included do
          after_find :decode_fields
          before_save :encode_fields
  
          @decoded = {}
      end
  
      def decoded(key, value = false)
          @decoded[key][:value] if @decoded.has_key? key
      end
  
  
      def decode_fields
          @decoded = {} if @decoded.nil?
          ENCODED.each do |field|
              if attributes[field]
                  @decoded[field] = {
                      value: JSON.parse(attributes[field]),
                      dirty: false
                  }
              end
          end
      end
  
      def encode_fields
          ENCODED.each do |field|
              if decoded[field] &amp;&amp; decoded[field][:dirty]
                  attributes[field] = @decoded[field][:value].to_json
              end
          end
      end
  end
  </code></pre>
  
  <p>Given this setup, I get the error <code>uninitialized constant EmbeddedData::ENCODED</code></p>
  
  <p>If I change the reference to self::ENCODED in the Concern I get the error:
      # is not a class/module</p>
  
  <p>I've even tried making a method on the concern <code>register_fields</code> that I can then call from the model, but the model just throws an unknown method error.</p>
  
  <p>Running out of ideas here and looking for help.</p>