简体   繁体   English

application.js 中的代码未在 Rails 中加载

[英]Code in application.js not loading in Rails

I just launched my web service and just found out that my application.js is not working...我刚刚启动了我的 web 服务,发现我的 application.js 无法正常工作......

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

$("body").on('click', 'ul#invite_links li#invite_link_facebook a', function () {
  var url = $(location).attr('href');
    FB.ui({
    method: 'send',
    link: url
  });
});

$("body").on('click', '#facebook_friends button', function () {
  var receiver_name = $(this).find(".facebook-friend-name").text();
  var receiver_img = $(this).find(".facebook-friend-avatar   img").attr("src");
  $("#facebook_avatar").val(receiver_img);
  $("#collaborator_user_account").val(receiver_name);
  $("#collaborator_user_account").attr("readonly", "readonly");
  $("#collaborator_job_name").focus();
});

$("body").on('click', '#modal-close', function () {
  $(".modal").hide();
});

$(document).ready(function() {
  $('.notice').stop().animate({'marginTop':'-30'},850).delay(3000).slideUp(500);
});

This should be working when user access work page and try to add collaborator through searching friends in facebook.当用户访问工作页面并尝试通过在 facebook 中搜索朋友来添加协作者时,这应该可以工作。 example here这里的例子

It is so because you are not requiring the current file itself. 之所以如此,是因为您不需要当前文件本身。 Following is how would you do so: 以下是您的处理方式:

//= require_self

Please note that //= require_tree . 请注意//= require_tree . does load the current tree/directory, but it doesn't load the code in the file: application.js itself. 确实会加载当前的树/目录,但不会加载文件application.js本身中的代码。

Edit: If still your code doesn't work, you have to have your JS code inside $(document).ready callback so that it gets executed when all the other asset files load properly. 编辑:如果仍然无法使用您的代码,则必须将JS代码放在$(document).ready回调中,以便在所有其他资产文件正确加载时执行该代码。

I had a similar problem, and in my case all I had to do was run yarn build --watch我遇到了类似的问题,就我而言,我所要做的就是运行yarn build --watch

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

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