如何使用AJAX从Javascript函数更新Rails表?

时间:2022-02-08 03:45:28

I'm new to Rails and AJAX and am stuck at how I can update a Rails table from a Javascript function with AJAX.

我是Rails和AJAX的新手,我一直纠结于如何用AJAX从Javascript函数中更新Rails表。

Specifically, I am working on a planner and when I drop a draggable div (this represents an item in my database) onto a calendar, I'd like to change the 'start date' for that item. I can retrieve the correct date upon placement, I just don't know how to update the Rails table variable with this new date.

具体地说,我正在处理一个计划器,当我将一个draggable div(它表示数据库中的一个项目)放到一个日历中时,我想要更改这个项目的“开始日期”。我可以在放置时获取正确的日期,我只是不知道如何使用这个新日期更新Rails表变量。

Normally, I would access it as: batch_ticket.start_date.

通常,我将以如下方式访问它:batch_ticketter .start_date。

From what I've seen, I need to make a remote AJAX call to update this variable but I'm stuck on how to do this. Any push in the right direction would be fantastic. Thanks!

根据我所看到的,我需要做一个远程AJAX调用来更新这个变量,但是我还是不知道怎么做。任何朝着正确方向的努力都将是不可思议的。谢谢!

1 个解决方案

#1


2  

checkout the :remote => true option available for rails forms. also look into creating an *.js.erb file which will be rendered back to the browser and executed after the remote form is submitted.

签出:remote => true选项,可用于rails表单。同时也要考虑创建一个*.js。erb文件,该文件将在提交远程表单后返回浏览器并执行。

#1


2  

checkout the :remote => true option available for rails forms. also look into creating an *.js.erb file which will be rendered back to the browser and executed after the remote form is submitted.

签出:remote => true选项,可用于rails表单。同时也要考虑创建一个*.js。erb文件,该文件将在提交远程表单后返回浏览器并执行。