我知道人们对此提出了很多要求,但是没有一个答案对我有用。我在使用JQuery提交的Rails 5中有一个表单(用于添加有关视频的信息)。现在的问题是,表单被提交了两次,每个条目实际上被创建了两次(两次发布请求),但是具有不同的ID。
一些答案说jquery被两次包含了,这是因为我在assets/javascripts/application.js
中
//= require jquery
//= require rails-ujs
//= require jquery_ujs
//= require_tree .
有人告诉我删除//= require jquery_ujs
,因为'rails_ujs'
已经需要它。但是,问题仍然存在。使表单一次提交的唯一方法是删除//= require jquery
因此,此表单在assets/javascripts/application.js
//= require jquery
//= require rails-ujs
//= require_tree .
尽管assets/javascripts/application.js
中的表单一次提交表单,但是某些使用jquery的组件(例如下拉列表)不再起作用(正常,因为它不存在),但是我感到困惑,因为表单仍然可以提交。
//= require rails-ujs
//= require_tree .
这是我创建视频的创建方法
def create
params[:rubric][:author] = session[:current_user_name]
rubric = Rubric.new(rubric_params)
@video = rubric.create_video(video_params)
@video.lastEdit = session[:current_user_name]
@video.save
flash[:notice] = "Video has been created and has following id:'#{@video.id}'"
redirect_to video_path(@video)
end
表单看起来像这样
<form action="/videos" method="POST" class="ui form" style="margin:0">
// A bunch of fields
<button style="color: white; margin: 20px 0 20px 0" class="ui huge submit blue basic button">Create</button>
如您所见,表格非常简单。 这是开发日志。请注意两个发帖请求
127.0.0.1 - - [15/Jul/2019:14:14:44 CDT] "GET /videos/new HTTP/1.1" 200 95453
http://localhost:3000/videos -> /videos/new
Started POST "/videos" for 127.0.0.1 at 2019-07-15 14:14:55 -0500
Processing by VideosController#create as HTML
Started POST "/videos" for 127.0.0.1 at 2019-07-15 14:14:56 -0500
Parameters: {"authenticity_token"=>"yJptxA22vfVZd3zyc1EfZ1HS8pYxpX/g3AiiQf9o7xdVxIARkNC7IKNv6XHXeASGEDjfng9mTwv+AW1sRIIQXQ==", "video"=>{"link"=>"trial 5", "presenter"=>" ", "segments"=>[{"cut"=>""}], "section"=>"", "topic"=>""}, "rubric"=>{"voice"=>"Not Applicable", "noise"=>"Not Applicable", "volume"=>"Not Applicable", "enhacements"=>"Not Applicable", "overallSmooth"=>"Not Applicable", "transition"=>"Not Applicable", "sharpFocus"=>"Not Applicable", "effects"=>"Not Applicable", "symbol"=>"Not Applicable", "informationMinimized"=>"Not Applicable", "conveyMessage"=>"Not Applicable", "wordingAccurate"=>"Not Applicable", "wordingAppropriate"=>"Not Applicable", "contentAccurate"=>"Not Applicable", "contentOrganized"=>"Not Applicable", "contentRelevant"=>"Not Applicable", "sequencing"=>"Not Applicable", "weblinks"=>"Not Applicable", "graphicsEffective"=>"Not Applicable", "graphicsDistraction"=>"Not Applicable", "graphicsQuality"=>"Not Applicable", "textAppropriate"=>"Not Applicable", "textConsistent"=>"Not Applicable", "textAmount"=>"Not Applicable", "background"=>"Not Applicable", "interactive"=>"Not Applicable", "studentControl"=>"Not Applicable", "shownPresenter"=>"Not Applicable", "videoLength"=>"Not Applicable", "personal"=>"Not Applicable", "moving"=>"Not Applicable", "engaging"=>"Not Applicable", "normalPace"=>"Not Applicable", "enunciation"=>"Not Applicable", "problem"=>"Maybe", "lecture"=>"Maybe", "review"=>"Maybe", "concept"=>"Maybe", "supplementary"=>"Maybe", "print"=>"Maybe", "view"=>"Maybe", "use"=>"Maybe"}}
Processing by VideosController#create as HTML
MONGODB | localhost:27017 | tops-development.find | STARTED | {"find"=>"users", "filter"=>{"_id"=>BSON::ObjectId('5cfa0270e367aa45e7d919d1')}, "sort"=>{"_id"=>1}, "limit"=>1, "singleBatch"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354330316000 type=uuid data=0x653cd176a18b4447...>}}
Parameters: {"authenticity_token"=>"yJptxA22vfVZd3zyc1EfZ1HS8pYxpX/g3AiiQf9o7xdVxIARkNC7IKNv6XHXeASGEDjfng9mTwv+AW1sRIIQXQ==", "video"=>{"link"=>"trial 5", "presenter"=>" ", "segments"=>[{"cut"=>""}], "section"=>"", "topic"=>""}, "rubric"=>{"voice"=>"Not Applicable", "noise"=>"Not Applicable", "volume"=>"Not Applicable", "enhacements"=>"Not Applicable", "overallSmooth"=>"Not Applicable", "transition"=>"Not Applicable", "sharpFocus"=>"Not Applicable", "effects"=>"Not Applicable", "symbol"=>"Not Applicable", "informationMinimized"=>"Not Applicable", "conveyMessage"=>"Not Applicable", "wordingAccurate"=>"Not Applicable", "wordingAppropriate"=>"Not Applicable", "contentAccurate"=>"Not Applicable", "contentOrganized"=>"Not Applicable", "contentRelevant"=>"Not Applicable", "sequencing"=>"Not Applicable", "weblinks"=>"Not Applicable", "graphicsEffective"=>"Not Applicable", "graphicsDistraction"=>"Not Applicable", "graphicsQuality"=>"Not Applicable", "textAppropriate"=>"Not Applicable", "textConsistent"=>"Not Applicable", "textAmount"=>"Not Applicable", "background"=>"Not Applicable", "interactive"=>"Not Applicable", "studentControl"=>"Not Applicable", "shownPresenter"=>"Not Applicable", "videoLength"=>"Not Applicable", "personal"=>"Not Applicable", "moving"=>"Not Applicable", "engaging"=>"Not Applicable", "normalPace"=>"Not Applicable", "enunciation"=>"Not Applicable", "problem"=>"Maybe", "lecture"=>"Maybe", "review"=>"Maybe", "concept"=>"Maybe", "supplementary"=>"Maybe", "print"=>"Maybe", "view"=>"Maybe", "use"=>"Maybe"}}
MONGODB | localhost:27017 | tops-development.find | SUCCEEDED | 0.103s
MONGODB | localhost:27017 | tops-development.find | STARTED | {"find"=>"users", "filter"=>{"_id"=>BSON::ObjectId('5cfa0270e367aa45e7d919d1')}, "sort"=>{"_id"=>1}, "limit"=>1, "singleBatch"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354379623340 type=uuid data=0xe9f93deece4846c7...>}}
MONGODB | localhost:27017 | tops-development.find | SUCCEEDED | 0.100s
MONGODB | localhost:27017 | tops-development.insert | STARTED | {"insert"=>"videos", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354379623340 type=uuid data=0xe9f93deece4846c7...>}, "documents"=>[{"_id"=>BSON::ObjectId('5d2cd0b222918603aecd6242'), "presenter"=>" ", "cuts"=>"", "section"=>"", "topic"=>"", "co...
MONGODB | localhost:27017 | tops-development.insert | STARTED | {"insert"=>"videos", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354330316000 type=uuid data=0x653cd176a18b4447...>}, "documents"=>[{"_id"=>BSON::ObjectId('5d2cd0b222918603aecd6244'), "presenter"=>" ", "cuts"=>"", "section"=>"", "topic"=>"", "co...
MONGODB | localhost:27017 | tops-development.insert | SUCCEEDED | 0.032s
MONGODB | localhost:27017 | tops-development.insert | STARTED | {"insert"=>"rubrics", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354330316000 type=uuid data=0x653cd176a18b4447...>}, "documents"=>[{"_id"=>BSON::ObjectId('5d2cd0b222918603aecd6243'), "author"=>"Pape Sow Traore", "voice"=>"Not Applicable", "noi...
MONGODB | localhost:27017 | tops-development.insert | SUCCEEDED | 0.039s
MONGODB | localhost:27017 | tops-development.insert | STARTED | {"insert"=>"rubrics", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354379623340 type=uuid data=0xe9f93deece4846c7...>}, "documents"=>[{"_id"=>BSON::ObjectId('5d2cd0b222918603aecd6241'), "author"=>"Pape Sow Traore", "voice"=>"Not Applicable", "noi...
MONGODB | localhost:27017 | tops-development.insert | SUCCEEDED | 0.101s
MONGODB | localhost:27017 | tops-development.insert | SUCCEEDED | 0.100s
MONGODB | localhost:27017 | tops-development.update | STARTED | {"update"=>"videos", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354330316000 type=uuid data=0x653cd176a18b4447...>}, "updates"=>[{"q"=>{"_id"=>BSON::ObjectId('5d2cd0b222918603aecd6244')}, "u"=>{"$set"=>{"lastEdit"=>"Pape Sow Traore"}}, "multi"=...
MONGODB | localhost:27017 | tops-development.update | STARTED | {"update"=>"videos", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70354379623340 type=uuid data=0xe9f93deece4846c7...>}, "updates"=>[{"q"=>{"_id"=>BSON::ObjectId('5d2cd0b222918603aecd6242')}, "u"=>{"$set"=>{"lastEdit"=>"Pape Sow Traore"}}, "multi"=...
MONGODB | localhost:27017 | tops-development.update | SUCCEEDED | 0.076s
MONGODB | localhost:27017 | tops-development.update | SUCCEEDED | 0.002s
Redirected to http://localhost:3000/videos/5d2cd0b222918603aecd6244
Redirected to http://localhost:3000/videos/5d2cd0b222918603aecd6242
Completed 302 Found in 3289ms
```