Friday 15 August 2014

ruby on rails - Convert Active Record set into an array of hashes -


I saw this ...

And wanted to make a method Which will allow me to set any scud or non-score record in an array of hashes. I added this to my model:

  def self.to_hash to_a.map (& serializable_hash) end   

However, I get this error < / P>

  name: error: 'to_a' method for undefined local variables or #; Class: 0x007fb0da2f2708 & gt;   

Any ideas?

You may also all on to_a A scope or current result will work fine on the set (such as User.active.to_hash ), but not directly on the model (such as User.to_hash ). Using all.to_a will work for both scenarios.

  def self.to_hash all.to_a.map (& serializable_hash) termination   

Note that all.to_a is slightly narrow Because all already gives an array, but in Rail 4 it will be necessary.

No comments:

Post a Comment