ryanbayona-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jul-05 03:04 UTC
rendering multiple views
Hi, How can i render multiple views in rails? For example i have two .rhtml files: header.rhtml -> a chunk of html codes to be rendered on top of the page sidebar.rhtml -> also a chunk of html, to be rendered in the right side of the page How can i call this .rhtml files from the controller and assign it to my layout? thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 5, 2008 at 1:04 PM, ryanbayona-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <ryanbayona-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How can i render multiple views in rails? > For example i have two .rhtml files: > header.rhtml -> a chunk of html codes to be rendered on top of the > page > sidebar.rhtml -> also a chunk of html, to be rendered in the right > side of the page > How can i call this .rhtml files from the controller and assign it to > my layout? thanks!You do this with "content_for" calls. In your layout file, have multiple yield commands... like this; <body> <div id="sidebar"> <%= yield :sidebar -%> </div> <div id="content"> <%= yield :content -%> </div> <div id="footer"> <%= yield :footer -%> </div> </body> Then in the partial: <% content_for :sidebar do -%> <%= render :partial => ''sidebar'' -%> <% end -%> <% content_for :footer do -%> <%= render :partial => ''footer'' -%> <% end -%> <p>This text ends up in the #Content div in the layout as it is the default</p> Hope that helps Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
oops I stuffed up on the example On Sat, Jul 5, 2008 at 4:45 PM, Mikel Lindsaar <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <body> > <div id="sidebar"> > <%= yield :sidebar -%> > </div> > <div id="content"> > <%= yield :content -%> > </div> > <div id="footer"> > <%= yield :footer -%> > </div> > </body>Should be: <body> <div id="sidebar"> <%= yield :sidebar -%> </div> <div id="content"> <%= yield -%> </div> <div id="footer"> <%= yield :footer -%> </div> </body> Sorry. Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryanbayona-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jul-05 09:34 UTC
Re: rendering multiple views
So I can call the render method in the Views? Can i also have multiple render method calls in the controller methods? Thanks.. On Jul 5, 2:46 pm, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> oops I stuffed up on the example > > On Sat, Jul 5, 2008 at 4:45 PM, Mikel Lindsaar <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > <body> > > <div id="sidebar"> > > <%= yield :sidebar -%> > > </div> > > <div id="content"> > > <%= yield :content -%> > > </div> > > <div id="footer"> > > <%= yield :footer -%> > > </div> > > </body> > > Should be: > > <body> > <div id="sidebar"> > <%= yield :sidebar -%> > </div> > <div id="content"> > <%= yield -%> > </div> > <div id="footer"> > <%= yield :footer -%> > </div> > </body> > > Sorry. > > Mikel > > --http://lindsaar.net/ > Rails, RSpec and Life blog....--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 5, 2008 at 7:34 PM, ryanbayona-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <ryanbayona-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So I can call the render method in the Views?Yes.> Can i also have multiple > render method calls in the controller methods?Never tried that, but that would not be good. Keep your view logic in the views, not in the controller. -- http://lindsaar.net/ Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 5, 10:34 am, "ryanbay...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <ryanbay...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So I can call the render method in the Views? Can i also have multiple > render method calls in the controller methods? > Thanks.. >Try it and find out. It will be a hell of a lot quicker than waiting for an answer from a mailing list. (Hint, check out the DoubleRenderError exception ). Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---