1

I am using rails to develop an application. After manipulating with my Models, I would like to send some arguments to my javascript/jQuery functions (library functions for UI etc..)

The only way I can think of is to build a hidden div and populate the values in it. So that when the document loads, onload function can process it and call some other function in turn.

Could somebody please suggest me a better way of doing this.

Cheers! ANi

anipendakur
  • 85
  • 10

2 Answers2

0

To expand on @mu's comment, script tags are valid html, right? You can dynamically create javascript inside a script tag in one of your views, and simply assign data into that javascript. After the page is loaded, you can use your javascript functions to access this data.

Matt
  • 10,434
  • 1
  • 36
  • 45
0

Watch 'Passing Data to Javascript' on RAILSCASTS. Ryan offers up three (of many) ways of doing it. One may suit what your looking for. http://railscasts.com/episodes/324-passing-data-to-javascript

Edit:

Also depending on how javascript heavy your front end is starting to get, you may want to look into Backbone.js. there are also two RailsCasts on that as well. It may be more than your looking to implement though. http://railscasts.com/episodes/323-backbone-on-rails-part-1

Taylor
  • 136
  • 1
  • 3