The Plan model has an objects field, which is stored in the database in json format.
def new @plan = Plan.new @restaurant = Restaurant.find(params[:restaurant_id]) @plans = @restaurant.plans respond_to do |format| format.html format.json { render json: @plans.distinct.pluck(:objects) } end end def plan_params params.require(:plan).permit(:restaurant_id, objects: [ :width, :height, :fill, :radius, :blendMode, :rotate, :strokeWidth, :stroke, :type, :x, :y]) end When I deduce object that turns out an array in an array:
{"objects":[[{"width":308,"height":248,"fill":"#fff","radius":0,"blendMode":"normal","rotate":0,"strokeWidth":1,"stroke":"#b9b9b9","type":"rectangle","x":84,"y":46},{"width":260,"height":150,"fill":"white","blendMode":"normal","rotate":0,"strokeWidth":1,"stroke":"#b9b9b9","type":"circle","x":497,"y":104},{"width":69,"height":51,"fill":"#fff","radius":0,"blendMode":"normal","rotate":0,"strokeWidth":1,"stroke":"#b9b9b9","type":"rectangle","x":149,"y":112}]]} How can I output to be only 1 array?
{"objects":[{...}]}
@plans.distinct.pluck(:objects)? - Mikhail Vaysman@plans.distinct.pluck(:objects)different way, not an array, but something like@plans.objects, when I do something like that in the console, it displays what it needs - Silentium