How to pass a javascript variable into a erb code in a js view?

前端 未结 8 2076
时光取名叫无心
时光取名叫无心 2020-11-27 06:19

I have this Javascript view in my Rails 3 project:

app/views/expenses/new_daily.js.erb

var i = parseInt($(\'#daily\').attr(\'data-num\')) + 1;
//$(\'         


        
8条回答
  •  臣服心动
    2020-11-27 06:51

    Let's make shure we understand each other. Your erb template (new_daily.js.erb) will be processed on the server side, ruby code will be evaluated (within <% %>), substitution made, and then resulting javascript will be sent to browser. On the client side the browser will then evaluate this javascript code and variable i will be assigned a value.
    Now when do you want to pass this variable and to what partial?

提交回复
热议问题