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 <div id="comment_<%= comment.id %>"> comment.cmnt comment.like </div> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jan-Christian Foeh
2008-Apr-20 16:11 UTC
Re: Problem with RJS, partials, controllers and life
> 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...-I4CJOCdi0N68rHFcjEY/OA@public.gmane.org}", :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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jan-Christian Foeh 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("comment...-I4CJOCdi0N68rHFcjEY/OA@public.gmane.org}", :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, > JanI 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---