In my controller i have the following
def index
if !params[:place_id].nil? || !params[:place_id].empty?
@restaurant = GoogleSearchedLocation.registered(params[:place_id])
else
redirect_to customers_url
end
end
While in my model I have the following scope defined
scope :registered , -> (place_id) { where(:place_id => place_id) }
Output is expected as below i.e in the form of array
< GoogleSearchedLocation id: 1, place_id: "ChIJSeoh6hkEGTkRsd0e1crAbHU", name: "Dunkin' Donuts", rating: 4.3, longitude: nil, latitude: nil, scope: "GOOGLE", created_at: "2015-10-15 10:59:23", updated_at: "2015-10-15 10:59:23">
I tried to convert it into object in my controller function like below
@restaurant1= @restaurant[0].each_slice().map{|a| GoogleSearchedLocation.new(a)}
But it's throwing error
undefined method `each_slice' for < GoogleSearchedLocation:0x00000005345cb0>
Can anyone explain the reason for error while we all know the each_slice() function . And kindly suggest a reasonable way to convert this kind of array into object
@restaurant.firstshould give you the first object ofActiveRecord relationrestaurants = GoogleSearchedLocation.registered(params[:place_id])and@restaurant = restaurants.first, or something like that, coz your scope always returns a collection of objects and its better if your variable name to reflect that