Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:18:45+00:00 2026-05-26T19:18:45+00:00

How to extract and save array from string parameter? I’m trying convert string beafore_create

  • 0

How to extract and save array from string parameter? I’m trying convert string beafore_create but this doesn’t work. When I comment before_create :waypoints Mongoid throw error:

Parameters: {
    "utf8"=>"✓", 
     "authenticity_token"=>"nehoT1fnza/ZW4XB4v27uZsfFjjOu/ucIhzMmMKgWPo=", 
     "trip"=>{
         "title"=>"test", 
         "description"=>"test", 
         "waypoints"=>"[[52.40637,16.92517],[52.40601,16.925040000000003],[52.405750000000005,16.92493],[52.40514,16.92463],[52.404320000000006,16.924200000000003]]"
     }
}

Completed 500 Internal Server Error in 1ms

Mongoid::Errors::InvalidType (Field was defined as a(n) Array, but received a String with the value "[[52.40637,16.92517],[52.40601,16.925040000000003],[52.405750000000005,16.92493],[52.40514,16.92463],[52.404320000000006,16.924200000000003]]".):

EDIT Thanks for help, now it work but I don’t know whether following approach is good. I remove before_create and change parameter name from waypoints to waypoints_s and def waypoints to def waypoints_s:

#Parameters:
#"waypoints"=>"[[52.40637,16.92517],[52.40601,16.925040000000003],[52.405750000000005,16.92493],[52.40514,16.92463],[52.404320000000006,16.924200000000003]]"
"waypoints_s"=>"[[52.40637,16.92517],[52.40601,16.925040000000003],[52.405750000000005,16.92493],[52.40514,16.92463],[52.404320000000006,16.924200000000003]]"

class Trip
  include Mongoid::Document
  field :title, :type => String
  field :description, :type => String
  field :waypoints, :type => Array

  #before_create :waypoints

  #def waypoints=(arg)
  def waypoints_s=(arg)
    if (arg.is_a? Array)
      #@waypoints = arg
      self.waypoints = arg
    elsif (arg.is_a? String) 
      #@waypoints = arg.split(',')
      self.waypoints = JSON.parse(arg)
    else 
      return false 
    end 
  end
end

class TripsController < ApplicationController
  def create
    @trip = Trip.create(params[:trip])
    @trip.save
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:18:46+00:00Added an answer on May 26, 2026 at 7:18 pm

    Parse the string as a JSON object:

    require 'json'
    
    waypoints = "[[52.40637,16.92517],[52.40601,16.925040000000003],[52.405750000000005,16.92493],[52.40514,16.92463],[52.404320000000006,16.924200000000003]]"
    JSON.parse(waypoints)
    
    => [[52.40637, 16.92517], [52.40601, 16.925040000000003], [52.405750000000005, 16.92493], [52.40514, 16.92463], [52.404320000000006, 16.924200000000003]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m using JAVA and I´m trying to extract or save images files from a
I am trying to extract data from XML file and save it my C#
Extract the number after #/ from my string: abcdefg#/123 .
I extract the audio from a bunch of flv files as an MP3. This
I am trying to extract the palette from a 5-6-5 (16bit) bitmap image that
I would like to extract elements from a deeply embedded list into an array.
I'm trying to use ruby and mongoid in order to extract some data from
Extract Images (any kind) from a ImageList and save it as a file with
I want to extract data from HTML table using Python script and save it
I am trying to extract data from XML. I generated C# classes using XSD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.