# Problem with RJS, partials, controllers and life

**URL:** <https://www.ruby-forum.com/t/problem-with-rjs-partials-controllers-and-life/135286>\
**Category:** Rails\
**Created:** [April 20, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/problem-with-rjs-partials-controllers-and-life/135286 "2008-04-20T17:51:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [April 20, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/problem-with-rjs-partials-controllers-and-life/135286/1 "2008-04-20T17:51:02Z")

</div>

Hello everyone I am new to Rails, to web development and to web forums.  
This is my first ever web forum account and my first ever post to one.  
Let this show you just how much I want to learn RoR. Allow me to  
illustrate a problem I am having:

To make this clear lets just say I have a website that is just a really  
basic blog where users can register, login and post comments onto the  
main page.

So now say we have two controllers and two models

site controller  
comment controller  
user model  
comment model

users have  
id  
name

comments have  
id  
user\_id  
cmnt varchar(255)  
like integer

OK so finally when a user goes to the website the first thing they see  
is the Index page which consists of all the comments entered by all  
users and each comment has a little link with text “I like this comment”

Each comment is in its own partial named \_comment.rhtml and this resides  
in the  
views\site directory

now within \_comment.rhtml we have

 comment.cmnt comment.like
 link\_to\_remote ("I Like this comment", :url =\> {:controller =\> "comment", :action =\> "add\_like", :id =\> comment})

Now to spare you more details my problem is that my add\_like function is  
in my comments controller and i have a add\_like.rjs file in the comments  
view directory because that’s where it looks for it. The problem is  
that in the rjs file which is basically just

page.replace\_html(“comment\_#{@comment.id}”, :partial =\> “comment”)

it looks for \_comment.rhtml in the quotes view directory!

I realize there’s a whole lot of wrong stuff going on here but I hope  
that there are some ridiculously smart people here who will know what  
I’m getting at and help me through this obstacle. Any help is greatly  
appreciated.

---

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [April 20, 2008, 6:12pm UTC](https://www.ruby-forum.com/t/problem-with-rjs-partials-controllers-and-life/135286/2 "2008-04-20T18:12:44Z")

</div>

> Now to spare you more details my problem is that my add\_like function is  
> in my comments controller and i have a add\_like.rjs file in the comments  
> view directory because that’s where it looks for it. The problem is  
> that in the rjs file which is basically just
> 
> page.replace\_html(“removed\_email\_address@domain.invalid}”, :partial =\> “comment”)
> 
> it looks for \_comment.rhtml in the quotes view directory!

Hi Leo,

you can load partials from other controllers by prefixing the  
controller name to them, e.g

:partial =\> “site/comment”

loads the comment partial from app/views/site, even if you are calling  
it from a different controller or view.

Hope this helps,  
Jan

---

<div class="post-metadata">

**Author:** ![leoncelot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/58f4c7/32.png) [@leoncelot](https://www.ruby-forum.com/u/leoncelot)\
**Post date:** [April 20, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/problem-with-rjs-partials-controllers-and-life/135286/3 "2008-04-20T18:54:29Z")

</div>

Jan-Christian F. wrote:

> > Now to spare you more details my problem is that my add\_like function is  
> > in my comments controller and i have a add\_like.rjs file in the comments  
> > view directory because that’s where it looks for it. ï¿½The problem is  
> > that in the rjs file which is basically just
> > 
> > page.replace\_html(“removed\_email\_address@domain.invalid}”, :partial =\> “comment”)
> > 
> > it looks for \_comment.rhtml in the quotes view directory!
> 
> Hi Leo,
> 
> you can load partials from other controllers by prefixing the  
> controller name to them, e.g
> 
> :partial =\> “site/comment”
> 
> loads the comment partial from app/views/site, even if you are calling  
> it from a different controller or view.
> 
> Hope this helps,  
> Jan

I love it when the solution is that simple. This indeed did work and I  
am more than happy for now. Thank you Jan for the quick response. I  
will definitely be using this site in the future.
