Aditya Rajgarhia
2006-Jul-20 06:22 UTC
[Rails] ActiveRecord/ActionController in javascript code
Hi, I have a javascript file for generating a menu when the user hovers over a link. These links are basically a list of logged in users. Now, in the menu I would like to have a link to "Display Profile" so that a user can view the profiles of other users. Also nice would be a picture in the menu. The problem is obviously that the javascript expects static links. But I want to have things like @user.name (ActiveRecord) or even a call to an ActionController action which could display the profile. If these are impossible then hopefully there must be some other way to achieve this. Any help would be greatly appreciated. Thanks! -- Posted via http://www.ruby-forum.com/.
Jonathan Gill
2006-Jul-20 07:16 UTC
[Rails] ActiveRecord/ActionController in javascript code
Hi Aditya> I have a javascript file for generating a menu when the user hovers over > a link. These links are basically a list of logged in users. Now, in the > menu I would like to have a link to "Display Profile" so that a user can > view the profiles of other users. Also nice would be a picture in the > menu. > > The problem is obviously that the javascript expects static links. But I > want to have things like @user.name (ActiveRecord) or even a call to an > ActionController action which could display the profile. > > If these are impossible then hopefully there must be some other way to > achieve this. Any help would be greatly appreciated. >How about, as a suggestion use a partial that generates the javascript array (im guessing the "static links" are in an array) then that partial could use a helper to do the lookup to activerecord and display the text you want. Does that help? Jonathan> Thanks! >
Brez! !!
2006-Jul-20 09:07 UTC
[Rails] Re: ActiveRecord/ActionController in javascript code
Having direct access to ActiveRecord in JS seems like a big violation of MVC.. you need to chk out RJS - it''s not going to give you this functionality out of the box but should prove insightful enough to get you a pretty clean solution. -- Posted via http://www.ruby-forum.com/.
Aditya Rajgarhia
2006-Jul-20 19:36 UTC
[Rails] Re: ActiveRecord/ActionController in javascript code
> How about, as a suggestion use a partial that generates the javascript > array (im guessing the "static links" are in an array) then that partial > could use a helper to do the lookup to activerecord and display the text > you want.Thanks for the reply, Jonathan. Well, the problem with that is still the same: how do I place the generated array within the javascript code itself? Or how to have the javascript code access the array generated by the partial? -- Posted via http://www.ruby-forum.com/.