# ActiveRecord/ActionController in javascript code

**URL:** <https://www.ruby-forum.com/t/activerecord-actioncontroller-in-javascript-code/99087>\
**Category:** Rails\
**Created:** [July 20, 2006, 8:22am UTC](https://www.ruby-forum.com/t/activerecord-actioncontroller-in-javascript-code/99087 "2006-07-20T08:22:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ar1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@ar1](https://www.ruby-forum.com/u/ar1)\
**Post date:** [July 20, 2006, 8:22am UTC](https://www.ruby-forum.com/t/activerecord-actioncontroller-in-javascript-code/99087/1 "2006-07-20T08:22:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ar1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@ar1](https://www.ruby-forum.com/u/ar1)\
**Post date:** [July 20, 2006, 9:17am UTC](https://www.ruby-forum.com/t/activerecord-actioncontroller-in-javascript-code/99087/2 "2006-07-20T09:17:30Z")

</div>

Hi Aditya

> 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

---

<div class="post-metadata">

**Author:** ![ar1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@ar1](https://www.ruby-forum.com/u/ar1)\
**Post date:** [July 20, 2006, 9:36pm UTC](https://www.ruby-forum.com/t/activerecord-actioncontroller-in-javascript-code/99087/3 "2006-07-20T21:36:38Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![ar1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@ar1](https://www.ruby-forum.com/u/ar1)\
**Post date:** [July 20, 2006, 11:06am UTC](https://www.ruby-forum.com/t/activerecord-actioncontroller-in-javascript-code/99087/4 "2006-07-20T11:06:58Z")

</div>

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.
