Topic: how I call a rails method from javascript

There is one swf file. When I click on that swf file it will return
user_id.
And below that swf file I have to show detail of the specific users. The
detail will come from database. Now the problem is that there is small
javascript function which will give me the user id. So from that
javascript function I wanna call rails method which will fetch data from
database and show it where I want.

so how I call a rails method from javascript ?

Re: how I call a rails method from javascript

You need an AJAX request.

Make a controller and action that respond to json format and fetch the data you need by user id, and make an ajax call to it. In jquery it would be like this:

$.get('/users/' + id + '.json', function(response) {
  // your js code that inserts data into the page
});

Last edited by bluesman.alex (2010-09-12 04:22:13)

Re: how I call a rails method from javascript

Thank you for the informative post.

Re: how I call a rails method from javascript

I also have similar problem. do u happen to know the tutorial for it? thank you big_smile