active-hash/active_hash

Methods not working on model.

Closed this issue · 1 comments

I have this model setup:

class FieldType < ActiveHash::Base
  self.data = [
      {:id => 1, :name => "text", :friendly_name => "Text"},
      {:id => 2, :name => "textarea", :friendly_ => "Text Area"},
      {:id => 3, :name => "image", :friendly_ => "Image"},
  ]
end

And I'm trying to list these field types for a select:

def field_types_for_select
  #FieldType.all.order('name asc').collect { |t| [t.friendly_name, t.name] }
  FieldType.pluck(:friendly_name, :name)
end

But I also get an error that order, collect or pluck are not defined.

How do I access this data? This works fine on other models, just not ActiveHash ones.

@iamdriz Hi. Sorry for late reply.
A workaround is

FieldType.all.sort_by(&:name).map { |data| [data.friendly_name, data.name] }

If you are interested in implementation of order and pluck, we are welcome for PR.
Thanks :)