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

  • SEARCH
  • Home
  • 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 6888909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:05:16+00:00 2026-05-27T06:05:16+00:00

My JavaScript serializes view fields and add waypoints array to post data, in controller

  • 0

My JavaScript serializes view fields and add waypoints array to post data, in controller each parameter separately add to Geo object encounters a waypoint parameter and it parse to array. Whether can be done a filter that would get these parameter and parse it so that I can use normal approach? Now in normal approach that is Geo.new(params[:geo]) rails returns (Field was defined as a(n) Array, but received a String with the value “[\”Paris, France\”,\”Stuttgart, Deutschland\”]”.).

Controller:

def create
  @geo = Geo.new
  @geo.waypoints = JSON.parse params[:geo][:waypoints] if params[:geo][:waypoints].is_a? String
  @geo.description = params[:geo][:description]
  @geo.start = params[:geo][:start]
  @geo.end = params[:geo][:end]
  @geo.save
  redirect_to geo_path(@geo), :notice => "Geo successfully submitted."
end

JS:

$('form').submit(function () {
    var waypoints = ["Paris, France", "Stuttgart, Deutschland"]
    var url = $(this).attr('action');
    var waypoints_temp_field = $('<input type="hidden" name="geo[waypoints]" />').val(JSON.stringify(waypoints)).appendTo(this);
    var postdata = $(this).serialize();

    $.post(url, postdata, function (callback) {
        // callback
    }, "json");
    return false;
});
  • 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-27T06:05:16+00:00Added an answer on May 27, 2026 at 6:05 am

    Well, couldn’t you change the waypoints_temp_field to post to something other than geo? For example:

    var waypoints_temp_field = $('<input type="hidden" name="waypoints" />')
                               .val(JSON.stringify(waypoints)).appendTo(this);
    

    Then in your controller, you could have:

    @geo = Geo.new(params[:geo])
    @geo.waypoints = JSON.parse(params[:waypoints]) if params[:waypoints])
    

    This way, you can process waypoints separately from everything else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass some data to javascript in my view. I only want
JavaScript post request like a form submit shows you how to submit a form
I need to deserialize some JavaScript object represented in JSON to an appropriate C#
For my mvc application I need to create Order object each having a list
I Have an Array of users that i want to pass into a view
I have a situation where I am sending data to a Controller via jQuery
I am trying to send a serialized object using JSON. Here is my view
I have a table with misc. data. Each row has a checkbox. This table
Do applet javascript calls serialize in any proper way? I'm considering implementing a model
JavaScript allows functions to be treated as objects--if you first define a variable as

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.