1

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

5
  • What is the value of @client.mobile in this instance? Commented Mar 19, 2015 at 12:51
  • What do you mean "both files are in one view folder"? Commented Mar 19, 2015 at 12:53
  • What you've written is the proper way, and the Ruby is definitely being embedded or you wouldn't see "" 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.mobile not containing what you think it contains. Commented Mar 19, 2015 at 12:54
  • @meagar, i am using ajax, so in my view i have autofill.js.erb which is executed in respond_to autofill method in controller Commented Mar 19, 2015 at 12:55
  • Check your web console logs. It will clear what js code server is returning. Commented Mar 19, 2015 at 12:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.