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 Miller <jackson-wKYWyQ94FGasTnJN9+BGXg@public.gmane.org> 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.
> 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.If you''re willing to run on edge Rails, would RJS Templates work for you? http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates Quoted by Cody at that URL, from rdocs: "Unlike conventional templates which are used to render the results of an action, these templates generate instructions on how to modify an already rendered page. This makes it easy to modify multiple elements on your page in one declarative Ajax response. Actions with these templates are called in the background with Ajax and make updates to the page where the request originated from."