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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:26:46+00:00 2026-05-27T23:26:46+00:00

Disclaimer: I’m a rails newbie, so I apologize if I’m going at this problem

  • 0

Disclaimer: I’m a rails newbie, so I apologize if I’m going at this problem entirely wrong. I’m using jQuery UI’s draggable functionality, and after a user drags an element, I need to add a new entry into a database. My javascript looks like this:

$(function() {
    $( ".staged" ).draggable({ appendTo: 'body',
        containment: 'window',
        scroll: false,
        helper: 'clone',
        stop: function(e,ui) {
            // around here, I'd like to create a new entry in the database called "placed_images"
            var url = this.getAttribute("src");
            x = ui.offset.left;
            y = ui.offset.top;
            var div = document.createElement("div");
            div.className += "placed";
            div.innerHTML = '<img src="'+url+'" class="placed" style="top:'+y+'px;left:'+x+'px;">'
            document.getElementById('page').appendChild(div);
            $(function() {
                $( ".placed" ).draggable();
            });
        }
    });
});

The above code is in the pages.js file in the javascript folder of my app. I know how to make a new entry in a database by using a form action that sends params to the “create” function in a controller. The code should have the same effect as:

form_for(:placed_image, :url => {:action => 'create'}) do |f| ...

Except without a form and it should happen asynchronously, without a page reload. Like I said, this might be a boneheaded way of going about this, I’m not sure. But if you know of a library, gem, or tutorial that might help me out, that’d be greaaaat.

  • 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-27T23:26:47+00:00Added an answer on May 27, 2026 at 11:26 pm

    Since you’re using jQuery, you should utilize jQuery’s built-in AJAX methods for communicating with the Rails server from javascript.

    jQuery has an $.ajax method: http://api.jquery.com/jQuery.ajax/

    Example:

    $(function() {
        $( ".staged" ).draggable({ appendTo: 'body',
            containment: 'window',
            scroll: false,
            helper: 'clone',
            stop: function(e,ui) {
                // generate 'placed_images' on server
                $.ajax({
                    data: { 'some_data_to_send_to_server':'any_data_goes_here' },
                    type: 'POST',
                    url: '/some_path_to_your_controller',
                    success: function () {
                        // it worked!  
                    },
                    error: function (response) {
                        // we had an error
                    }
                });
    
                var url = this.getAttribute("src");
                x = ui.offset.left;
                y = ui.offset.top;
                var div = document.createElement("div");
                div.className += "placed";
                div.innerHTML = '<img src="'+url+'" class="placed" style="top:'+y+'px;left:'+x+'px;">'
                document.getElementById('page').appendChild(div);
                $(function() {
                    $( ".placed" ).draggable();
                });
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: super new to rails. I'm using Rails 3.2 Anyways, I'm trying to create
Disclaimer: this question is purely informational and does not represent an actual problem I'm
Disclaimer: I apologize that this question is so long. I have added code as
Disclaimer: this is a (frustrating) homework related problem. I'm having odd results when I
Disclaimer: This is a homework problem. As should be evident, I am trying to
Disclaimer: I'm pretty terrible with multithreading, so it's entirely possible I'm doing something wrong.
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
Disclaimer: this question is driven by my personal curiosity more than an actual need
Disclaimer: I am using ExtJS 3, but I don't think it's very relevant 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.