[英]Using w2ui with Rails: Submitting a form
I am trying to build a Rails application with w2ui . 我正在尝试使用w2ui构建一个Rails应用程序。
I have hit my first snag when trying to submit a form built with w2ui. 尝试提交使用w2ui构建的表单时,我遇到了第一个障碍。
I have a simple model called Project
with two attributes: name
and description
. 我有一个名为
Project
的简单模型,具有两个属性: name
和description
。
The standard, scaffolded form built by Rails submits the form data as follows: Rails构建的标准脚手架表单提交的表单数据如下:
project[name]:Test Project
project[description]:A description
However, the form data submitted by w2ui looks as follows: 但是,w2ui提交的表单数据如下所示:
record[project[name]]:Test Project
record[project[description]]:A description
That is, w2ui wraps the data further in a record
variable, which means I must either change the controller in Rails, which I am not wanting to do, or find a way to get w2ui to not wrap the data the way it does. 也就是说,w2ui将数据进一步包装在一个
record
变量中,这意味着我必须在我不想做的Rails中更改控制器,或者找到一种方法来使w2ui不再按照它的方式包装数据。
My code for w2ui is taken pretty much straight from their demos: 我的w2ui代码几乎直接来自其演示:
$(function () {
$('#project_form').w2form({
name : 'project_form',
url : '/projects.json',
fields: [
{ name: 'project[name]', type: 'text', required: true },
{ name: 'project[description]', type: 'text' }
],
actions: {
reset: function () {
this.clear();
},
save: function () {
this.submit(); // tried .save() as well, same result
}
}
});
});
First prize would be if w2ui could be configured to do this. 一等奖将是如果可以将w2ui配置为执行此操作。 Any ideas?
有任何想法吗? I don't see anything in the w2ui docs...
我在w2ui文档中什么都看不到...
I faced the same problem and straight away could not get a solution. 我遇到了同样的问题,无法立即解决。 I added the below to form options, it just copies all params inside record to post data.
我在表单选项中添加了以下内容,它仅将记录内的所有参数复制到发布数据中。
onSubmit: function(formName, formObj){
$.extend(formObj.postData, formObj.postData.record);
},
Its been long you have asked this question, if you knew a better solution please let me know. 您问这个问题已经很久了,如果您知道更好的解决方案,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.