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;
//$(\'
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?
Yes you can pass the value by using jquery;
<%=f.text_field :email ,:id=>"email_field" %>
<script type="text/javascript">
var my_email= "my@email.com"
$(document).ready(function(){
$("#email_field").val(my_email);
});
</script>