我正在使用Turbolinks,在我的videos/upload.js.erb
中,我有这个:
$(document).on("page:change", "#video-submit", function() {
console.log("Upload.js.erb has been executed");
});
这是从这个模态中执行的:
<div id="overlay"> </div>
<div class="popup" id="add-video-step-1">
<div class="titles clearfix">
<h2>Upload a Video</h2>
<p><i>Step 1 of 2 - TESTING 1, 2, 3</i></p>
</div>
<div class="content">
<% if @family_tree %>
<%= simple_form_for([@family_tree, @video], :remote => true) do |f| %>
<div class="column">
<div class="f-row">
<%= f.input :title, label: "Title:" %>
</div>
## truncated for brevity
</div>
<%= f.button :submit, "Add Video", id: "video-submit" %>
<% end %>
<% end %>
</div> <!-- //content -->
</div> <!-- //popup -->
在我的服务器日志中,这就是我所看到的:
Started POST "/family_trees/1/videos" for 127.0.0.1 at 2014-12-02 10:19:16 -0500
Processing by VideosController#create as JS
Parameters: {"utf8"=>"✓", "video"=>{"title"=>"Blah", "description"=>"blah blah blah blah", "circa"=>"", "user_ids"=>[""]}, "commit"=>"Add Video", "family_tree_id"=>"1"}
User Load (2.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
## truncated for brevity
Redirected to http://localhost:3000/videos/59/upload
Completed 302 Found in 32ms (ActiveRecord: 15.5ms)
Started GET "/videos/59/upload" for 127.0.0.1 at 2014-12-02 10:19:16 -0500
Processing by VideosController#upload as JS
Parameters: {"video_id"=>"59"}
User Load (2.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
## truncated for brevity
Rendered videos/_upload_video.html.erb (3.3ms)
Rendered videos/_upload_video.html.erb (0.6ms)
Rendered videos/_upload_video.html.erb (0.9ms)
Rendered videos/_upload_video.html.erb (1.0ms)
Rendered videos/upload.js.erb (22.8ms)
Completed 200 OK in 298ms (Views: 31.7ms | ActiveRecord: 8.9ms)
这是我的VideoController
:
def create
authorize! :read, @family_tree
@video = Video.new(video_params)
respond_to do |format|
if @video.save
format.html { redirect_to video_upload_path(@video) }
else
format.html { render action: 'new' }
format.json { render json: @video.errors, status: :unprocessable_entity }
end
end
end
def upload
authorize! :read, @family_tree
@video = Video.find(params[:video_id])
@upload_info = Video.token_form(@video, video_save_video_path(@family_tree, @video))
respond_to do |format|
format.html
format.js
end
end
然而,当我按下我的模态中的“添加视频”提交按钮时,我看不到任何输出到我的JS控制台。
导致这种情况的原因是什么?
修改1
为了它的价值,我也尝试了document.on("page:load")
,但这不起作用。我没有通过所有TL选项 - 不确定它们是否相关。