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 9189401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:13:42+00:00 2026-06-17T20:13:42+00:00

I have a Sinatra app which loads information from an external API and displays

  • 0

I have a Sinatra app which loads information from an external API and displays it on a page. This is done in Sinatra which gets the information and puts it a temporary model instance (which is NOT saved), so it is easier to access all its propertys in the view.

Now when the user clicks a link I want the model instance to be saved to the database, which I think only can be done via AJAX etc. because the last request already finished and none of the instances is still alive. I thought I needed to extract all the information of the corresponding HTML elements and make an AJAX-Post to another route.

My problem is now, I want to be able to create(and save) the model using @model = Model.create(params[:model]). It would be clear what to do using a form, but that is not an option because all the data is displayed within a table and each table row is one instance of the model.

How do I serialize the data from the table row in which the clicked link is, so I can use it as described above?

UPDATE

  • I am using MULTIPLE instances of the object class, each in one tablerow!
  • I am using DataMapper, only the temporary objects are not stored!
  • I dont want to clutter up my whole setup!
  • 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-06-17T20:13:43+00:00Added an answer on June 17, 2026 at 8:13 pm

    I found a pretty easy solution. It was nothing more than getting all the required values from the DOM and putting them into an Array!

    application.js:

    $(".enable").click(function() {
        var table_row = $(this).closest("tr");
        var model_array = new Array;
        var elements_with_information = jRow.find("[name]");
    
        elements_with_information.each(function() {
                // Doing some checking on which kind of element 
                // it actually is and then basically doing:
                model_array.push($(this).text());
        });
    
        // Constructing nested array to use `params[:model]`
        var data = { "model" : {
            "property1": model_array[0],
            "property2": model_array[1]
        }};
    
        // Now doing the AJAX request
        $.ajax({
            url: "/model/doshit",
            type: "POST",
            data: data
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Sinatra app, that uses omniauth which constantantly gets this error attack
I have a small Sinatra app which generates html fragments for me from an
I have a sinatra app with a page that shows some information about the
I have got Sinatra/Rails app and an action which starts some long process. Ordinary
In my sinatra app i have a form which is used to submit data
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I have a Sinatra app which would be used by different clients. I wish
I have a simple mongodb collection which stores tweets directly from the twitter api
The code below is from a Sinatra app (that uses DataMappe), which I am
I have a Sinatra app which uses DataMapper as it's ORM, it's deployed to

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.