ruby on rails - Undefined method pluck for array? -


so have data stucture:

+[#<folder id: 1, name: "mollitia", parent_id: nil, user_id: 1, created_at: "2014-06-27 16:00:59", updated_at: "2014-06-27 16:00:59">, + #<folder id: 2, name: "porro", parent_id: 1, user_id: 1, created_at: "2014-06-27 16:00:59", updated_at: "2014-06-27 16:00:59">,  + #<folder id: 3, name: "omnis", parent_id: 2, user_id: 1, created_at: "2014-06-27 16:00:59", updated_at: "2014-06-27 16:00:59">] 

which returned self.ancestors can pluck names?

def pwd     self.ancestors.pluck(:name) end 

the above results in

undefined method `pluck' #<array:0x007ff4da780290> 

update

awesome print of structure:

[     [0] #<folder:0x007fd2946a5f18> {                 :id => 3,               :name => "blanditiis",          :parent_id => 2,            :user_id => 1,         :created_at => fri, 27 jun 2014 18:04:02 utc +00:00,         :updated_at => fri, 27 jun 2014 18:04:02 utc +00:00     },     [1] #<folder:0x007fd2946ad1c8> {                 :id => 2,               :name => "neque",          :parent_id => 1,            :user_id => 1,         :created_at => fri, 27 jun 2014 18:04:02 utc +00:00,         :updated_at => fri, 27 jun 2014 18:04:02 utc +00:00     },     [2] #<folder:0x007fd2946b80c8> {                 :id => 1,               :name => "ut",          :parent_id => nil,            :user_id => 1,         :created_at => fri, 27 jun 2014 18:04:02 utc +00:00,         :updated_at => fri, 27 jun 2014 18:04:02 utc +00:00     } ] 

pluck used rails change association query against database. change select * select [attr] [attr] argument pluck. since it's array, can't use it. should instead use regular old map ruby. in case, like:

def pwd   self.ancestors.map(&:name) end 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -