I am looking for how to create a dynamic JavaScript within Rails and
coming up empty. I am sure this is probably covered somewhere but I
am jost not having any luck finding it.
Basically, I want a controller that creates a JavaScript that can be
included by HTML outside of the Rails app. This JavaScript need to
take into account the Rails session information.
Can someone point me in the right direction?
On 12/12/05, Jackson M. [email protected] wrote:
I am looking for how to create a dynamic JavaScript within Rails and
coming up empty. I am sure this is probably covered somewhere but I
am jost not having any luck finding it.
Basically, I want a controller that creates a JavaScript that can be
included by HTML outside of the Rails app. This JavaScript need to
take into account the Rails session information.
I’ve done this myself. Here is what you need to do.
-
Create a custom controller (I used “CustomJavaScript”). If you use
just javascript, I believe it will interfere with the regular
javascript folder. I didn’t try it out though.
-
Create a method / view for each dynamic javascript.
-
Fill out the view with the javascript, interspercing the dynamic
information where needed.
-
You might need to overwrite the default headers for the files to
be served correctly.
-
Link to the dynamic javascript using /ControllerName/MethodName
Enjoy! Let me know if you have more difficulties.