Вопрос по mysql, ruby-on-rails, database, arrays, json – хранение данных JSON в mysql

9

Error: User Rate Limit Exceeded

ID, name, address, phone, email, etc...

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

[ "[email protected]", "[email protected]", "[email protected]" ]

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Ваш Ответ

3   ответа
8

Saving arrays, hashes, and other non-mappable objects in text columns

0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

module MultiAttr

  def self.included(base)
    base.send :extend, ClassMethods
  end

  module ClassMethods
    def multi_attr(*args)
      args.each do |attr_name|
        class_eval <<-EOF
          has_many attr_#{attr_name}, :class_name => "MultiAttributes", :as => :owner,
             :conditions => {:key => '#{attr_name.singularize}'}

          def add_#{attr_name.singularize}(val)
            self.attr_#{attr_name}.create(:key => #{attr_name.singularize}, :value => val)
            #{attr_name}
          end

          def #{attr_name}
            self.attr_#{attr_name}.map(&:to_attr_model)
          end

        EOF
      end
    end

  end


end

class AttrModel < String

  def initialize(record)
    @record = record
    super(record.value)
  end

  def remove
    @record.destroy
  end

end


#owner_type, owner_id, key, value
class MultiAttribute < ActiveRecord::Base
  belongs_to :owner, :polymorphic => true

  def to_attr_model
    @attr_model ||= AttrModel.new(self)
  end
end

Error: User Rate Limit Exceeded

class User < ActiveRecord::Base
  include MultiAttr
  multi_attr :emails, :addresses
end

user.emails #=> ["[email protected]"]
user.add_email "[email protected]" #=> 
user.emails.first.remove

Error: User Rate Limit Exceeded

1

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Nick Sanders
Error: User Rate Limit Exceededorganization_idError: User Rate Limit Exceededothertable_idError: User Rate Limit Exceeded
Error: User Rate Limit Exceededen.wikipedia.org/wiki/Junction_tableError: User Rate Limit ExceededIDError: User Rate Limit ExceededTypeError: User Rate Limit Exceededtelephone_idError: User Rate Limit Exceeded

Похожие вопросы