简体   繁体   中英

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

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

but when i click on checkbox i get an error of undefined method updateDeal any one can help??

function is misspelled (it's typed fucntion in your code)

:)

you can do it in this way also , but it requires 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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