简体   繁体   English

Rails 4资产管道如何调用功能

[英]Rails 4 asset pipeline how to call function

I know this is simple but I need help. 我知道这很简单,但我需要帮助。 suppose I have a view where I have a checkbox like 假设我有一个视图,其中有一个复选框

<%= check_box_tag "sometext", "id", false, :onclick => "updateDeal()" %>

and I have a file in /assets/javascript/deals.js.coffee where I have this function 并且我在/assets/javascript/deals.js.coffee中有一个文件,其中有此功能

function updateDeal(){
  alert('call');
}

but when i click on checkbox i get an error of undefined method updateDeal any one can help?? 但是,当我单击复选框时,出现未定义方法updateDeal的错误,任何人都可以帮忙?

function is misspelled (it's typed fucntion in your code) 函数拼写错误(在您的代码中键入了fucntion)

:) :)

you can do it in this way also , but it requires jquery. 您也可以通过这种方式进行操作,但需要使用jquery。

$("#id").change(function(){
    if ($(this).is(":checked")){
      alert("checked");
    }
    else{
      alert("not checked");
    }
 });

u can convert it to coffee script also. 您也可以将其转换为咖啡脚本。 see: http://js2coffee.org/ copy and paste this code and you will get coffee script 请参阅: http : //js2coffee.org/复制并粘贴此代码,您将获得coffee脚本

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

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