Sign Up
Tutor Hunt on twitter Tutor Hunt on facebook

Tutor HuntQuestions

Tutor Hunt Questions

Can i use javascri pt variable inside erb tag ?
23 months ago

Ruby On Rails Question asked by Fakhir

Know the Answer?

Please enter your response to the question below. The student will get a notification as soon your response has been approved by our moderation team.

Submit Answer

1 Answer

Hi,

It depends on what you are doing. If you want to execute Javascri pt in erb it can be done simply by putting

<scri pt>
var foo
//Do something with foo
<scri pt/> inside your erb template.


However, if you want to pass a variable from one file to another you will need to use something called Ajax. Erb is a templating engine (simply turns ruby to html) and this happens on the server. Html and JS are run on client side (also known as your browser). Therefore, because erb is rendered on the server side first you will need to call back to your server once the html and JS have run in your browser (client side). This is done using Ajax.
Look up railscasts on Ajax!

If you just want to know what the erb tag for JS is, you can use something like: javascri pt_tag "alert(`This is a test`)".

Hope this helps a little. Without more information I can`t be more specific!

All the best.
Answered by Quinn | 14 months ago
    Rate Up  Rate Down     
Ask an Academic Question
Popular Links
© 2005-2017 Tutor Hunt - All Rights Reserved

Privacy | Copyright | Terms of Service
loaded in 0.000 seconds
twitter    facebook