Creating JavaScript


#1

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?


#2

On 12/12/05, Jackson M. removed_email_address@domain.invalid 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.

  1. 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.

  2. Create a method / view for each dynamic javascript.

  3. Fill out the view with the javascript, interspercing the dynamic
    information where needed.

  4. You might need to overwrite the default headers for the files to
    be served correctly.

  5. Link to the dynamic javascript using /ControllerName/MethodName

Enjoy! Let me know if you have more difficulties.