简体   繁体   English

如何手动包含remotipart js?

[英]how to manually include remotipart js?

I need to conditionally use the remotipart gem.我需要有条件地使用 remotipart gem。 The [docs][1] say just add it to application.js: [docs][1] 说只需将其添加到 application.js:

//= require jquery.remotipart

But I don't want it to be included with every single view, instead I want to conditionally include it, however when I try:但是我不希望它包含在每个视图中,而是有条件地包含它,但是当我尝试时:

<%= javascript_include_tag "jquery.remotipart" %>

I get an error.我收到一个错误。 How do i reference a js included as part of a gem generically, and remotipart js specifically?我如何一般地引用作为 gem 一部分包含的 js,特别是 remotipart js?

Thanks, Kevin谢谢,凯文

But I don't want it to be included with every single view, instead I want to conditionally include it, however when I try:但是我不希望它包含在每个视图中,而是有条件地包含它,但是当我尝试时:

What means conditionally in this context?在这种情况下,有条件地意味着什么? The most simplest way would be最简单的方法是

<%= javascript_include_tag "jquery.remotipart" if condition %>

Also you could use content_for like this on the views where you want to include it:您也可以像这样在要包含它的视图上使用content_for

# in your view
<% content_for :js do %>
  <%= javascript_include_tag "jquery.remotipart" %>
<% end %>

# in your layout.html.erb
<%= yield :script %>

https://apidock.com/rails/ActionView/Helpers/CaptureHelper/content_for https://apidock.com/rails/ActionView/Helpers/CaptureHelper/content_for

If you meant that you get an error that the JS file can't be found, please update your question with what library (webpacker, sprockets) and Rails version you use.如果您的意思是您收到无法找到 JS 文件的错误,请使用您使用的库(webpacker、sprockets)和 Rails 版本更新您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM