Hi, I have a block of code that is used by the layout file (html.erb) of every view. What is the best way to include this piece of code in all layout files? Can I actually include a Ruby file in an html.erb file, analogous to how files are included in PHP? Thanks, Amrita --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
There is usually only one layout file. What are you trying to do? Views can share code by using helpers. You put them in application_helper.rb.> I have a block of code that is used by the layout file (html.erb) of > every view. What is the best way to include this piece of code in all > layout files? > > Can I actually include a Ruby file in an html.erb file, analogous to > how files are included in PHP? >There is no need to do a "include", helper methods in application_helper.rb are automatically made available to all the views. -- http://www.rubyplus.org/ Free Ruby and Rails Screencasts --~--~---------~--~----~------------~-------~--~----~ 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 Wed, 2008-07-16 at 14:36 -0700, amrita wrote:> Hi, > > I have a block of code that is used by the layout file (html.erb) of > every view. What is the best way to include this piece of code in all > layout files? > > Can I actually include a Ruby file in an html.erb file, analogous to > how files are included in PHP?---- I don''t know that this is a ''best'' way but I have app/view/shared and then in the appropriate area in my layout, I have... <%= render :partial => "shared/name_of_shared_code" %> Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! I gathered something was wrong with the way my application was built. So, I shifted to a single layout file and specified the layout in the application controller. But its always good to know how code can be shared. Thanks, Craig and Bala. On Jul 16, 3:13 pm, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> On Wed, 2008-07-16 at 14:36 -0700, amrita wrote: > > Hi, > > > I have a block of code that is used by the layout file (html.erb) of > > every view. What is the best way to include this piece of code in all > > layout files? > > > Can I actually include a Ruby file in an html.erb file, analogous to > > how files are included in PHP? > > ---- > I don''t know that this is a ''best'' way but I have app/view/shared and > then in the appropriate area in my layout, I have... > > <%= render :partial => "shared/name_of_shared_code" %> > > Craig--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---