I have autofill.js.erb file in which should change value of input field with id request_mobile to @client.mobile, where @client.mobile is defined in autofill method. So i guess it should be accessible in autofill.js.erb file. both files are in one view folder.
$("#request_mobile").val("<%= escape_javascript @client.mobile %>");
But what i get is:
$("#request_mobile").val("");
So my ruby is not embedded int JS or something like that. What is the proper way of writing js.erb files.
Also trying :
$("#request_mobile").val("<%= @client.mobile %>");
doesn't help
asked Mar 19, 2015 at 12:47
yerassyl
3,0686 gold badges45 silver badges69 bronze badges
1 Answer 1
Sorry all, that was my fault. Actually everything works fine. I just didn't notice that in my db actually all mobile fields are empty.
$("#request_mobile").val("<%= escape_javascript @client.name %>");
$("#request_mobile").val("<%= @client.name %>");
Both work fine.
answered Mar 19, 2015 at 13:00
yerassyl
3,0686 gold badges45 silver badges69 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
@client.mobilein this instance?""in the output. You would see the original string of Ruby source code between<%=and%>. At this point, it's pretty clearly a case of@client.mobilenot containing what you think it contains.