Problem with RJS, partials, controllers and life

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.

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(“[email protected]}”, :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

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(“[email protected]}”, :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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs