I am new to Rails and am wondering how to share code across views. I have two views and want to share website logo & header. Any thoughts would be very helpful. 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 -~----------~----~----~----~------~----~------~--~---
Use a partial. It''s just a file that starts with an underscore in your views folder. And then call it via render :partial => :logo All partials & views can access instance variables set in your controller. Partials can also be passed local variables through a :locals hash. http://railsbrain.com/api/rails-1.2.3/doc/index.html?a=M000463&name=render Vish On 8/20/07, Gandalf <gandalf.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am new to Rails and am wondering how to share code across views. I > have two views and want to share website logo & header. Any thoughts > would be very helpful. > > 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 -~----------~----~----~----~------~----~------~--~---
You can use the layout file do that. Look at the following railscasts. it will clarify how layout works (it is a 7 min video) http://railscasts.com/episodes/7 Emmanuel ----- Original Message ---- From: Gandalf <gandalf.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: Ruby on Rails: Talk <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, August 20, 2007 10:19:32 AM Subject: [Rails] Sharing code in views I am new to Rails and am wondering how to share code across views. I have two views and want to share website logo & header. Any thoughts would be very helpful. Thanks. ____________________________________________________________________________________ Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You need to use layouts. Create one called application.rhtml which is where you keep the site-wide html. For an excellent introduction to layouts, see this screencast: http://railscasts.com/episodes/7 Hope that helps, DAZ On Aug 20, 6:19 pm, Gandalf <gandalf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am new to Rails and am wondering how to share code across views. I > have two views and want to share website logo & header. Any thoughts > would be very helpful. > > 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 -~----------~----~----~----~------~----~------~--~---
These are the most common and simple ways of sharing code: You have two methods, depending on what you want to achieve. A layout under app/views/layout allows you to declare a page that serves as a shell for your content and then you can add a content_for_layout reference where you want your content to appear. You can even have multiple layouts. Another way to share code is to create partials, such as a common header or footer, that your views can include. Paul On Aug 20, 2007, at 1:19 PM, Gandalf wrote:> > I am new to Rails and am wondering how to share code across views. I > have two views and want to share website logo & header. Any thoughts > would be very helpful. > > 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 -~----------~----~----~----~------~----~------~--~---