Say i want to include the same chunck of text (a menu on a webpage for example) on each page. Is there a method by which I can save the HTML in a text file and call it up later? Is there a better way? I know ruby has "puts" but i can''t use that b/c it does not work with my webhost (dreamhost.com) Any suggestions? -- Posted via http://www.ruby-forum.com/.
For a menu you would usually put that in a layout, then in your controllers you can specify that layout using... layout "mylayout" Inside your layout you would do something like... <html> <head> ...head stuff... </head> <body> ...menu bar html... <%= yield %> </body> </html> The <%= yield%> line puts what would usually be appearing without a layout in its place. Good Luck! ~Jamie www.jamiequint.com jamiequint@gmail.com On 7/24/06, Mason Kessinger <masonkessinger@gmail.com> wrote:> > Say i want to include the same chunck of text (a menu on a webpage for > example) on each page. Is there a method by which I can save the HTML in > a text file and call it up later? Is there a better way? > > > I know ruby has "puts" but i can''t use that b/c it does not work with my > webhost (dreamhost.com) > > Any suggestions? > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060725/8c9e8ccc/attachment-0001.html
You want layouts.. Create ./app/views/layouts/application.rhtml Try something like ----- Hello World from the header! <%= @content_for_layout %> Hello world form the footer! ----- On 7/24/06, Mason Kessinger <masonkessinger@gmail.com> wrote:> > Say i want to include the same chunck of text (a menu on a webpage for > example) on each page. Is there a method by which I can save the HTML in > a text file and call it up later? Is there a better way? > > > I know ruby has "puts" but i can''t use that b/c it does not work with my > webhost (dreamhost.com) > > Any suggestions? > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060725/8e017496/attachment.html
If you want the menu system to be available to your entire application, put it in /app/views/layouts/application.rhtml. It will automatiaclly be used by all controllers without having to use the layout command at the top of each controller. On 7/24/06, Jamie Quint <jsquintz@gmail.com> wrote:> > For a menu you would usually put that in a layout, then in your > controllers you can specify that layout using... > > layout "mylayout" > > Inside your layout you would do something like... > > <html> > <head> > ...head stuff... > </head> > <body> > ...menu bar html... > <%= yield %> > </body> > </html> > > The <%= yield%> line puts what would usually be appearing without a layout > in its place. > > Good Luck! > > ~Jamie > www.jamiequint.com > jamiequint@gmail.com > > > On 7/24/06, Mason Kessinger <masonkessinger@gmail.com> wrote: > > > > Say i want to include the same chunck of text (a menu on a webpage for > > example) on each page. Is there a method by which I can save the HTML in > > a text file and call it up later? Is there a better way? > > > > > > I know ruby has "puts" but i can''t use that b/c it does not work with my > > > > webhost (dreamhost.com) > > > > Any suggestions? > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- "Impossible is nothing." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060725/401685ce/attachment.html
For something like a nav, that will appear on all pages, a layout is what you want to use, like Jamie mentioned. If you have a chunk of html that will be used on some pages, but not all, look into using a partial. -TJ On 7/24/06, Jamie Quint <jsquintz@gmail.com> wrote:> For a menu you would usually put that in a layout, then in your controllers > you can specify that layout using... > > layout "mylayout" > > Inside your layout you would do something like... > > <html> > <head> > ...head stuff... > </head> > <body> > ...menu bar html... > <%= yield %> > </body> > </html> > > The <%= yield%> line puts what would usually be appearing without a layout > in its place. > > Good Luck! > > ~Jamie > www.jamiequint.com > jamiequint@gmail.com > > > On 7/24/06, Mason Kessinger <masonkessinger@gmail.com> wrote: > > Say i want to include the same chunck of text (a menu on a webpage for > > example) on each page. Is there a method by which I can save the HTML in > > a text file and call it up later? Is there a better way? > > > > > > I know ruby has "puts" but i can''t use that b/c it does not work with my > > webhost (dreamhost.com) > > > > Any suggestions? > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On 7/25/06, Stephen <sblackstone@gmail.com> wrote:> > You want layouts.. > > Create ./app/views/layouts/application.rhtml > > Try something like > > ----- > Hello World from the header! > <%= @content_for_layout %> > Hello world form the footer! > > ----- > > > > > > On 7/24/06, Mason Kessinger <masonkessinger@gmail.com> wrote: > > > Say i want to include the same chunck of text (a menu on a webpage for > > example) on each page. Is there a method by which I can save the HTML in > > a text file and call it up later? Is there a better way? > > > > > > I know ruby has "puts" but i can''t use that b/c it does not work with my > > > > webhost (dreamhost.com) > > > > Any suggestions? > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsAnother alternative to this is to use the content_for method In you view <% content_for( "menu") do %> erb for menu here <% end %> and then in your layout <%= yield :menu %> This should put your menu code in. If it''s not right I''ll check then syntax when I get home Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060725/7eefb4b2/attachment-0001.html
On 7/25/06, Daniel N <has.sox@gmail.com> wrote:> > > > On 7/25/06, Stephen <sblackstone@gmail.com> wrote: > > > You want layouts.. > > Create ./app/views/layouts/application.rhtml > > Try something like > > ----- > Hello World from the header! > <%= @content_for_layout %> > Hello world form the footer! > > ----- > > > > > > On 7/24/06, Mason Kessinger < masonkessinger@gmail.com> wrote: > > > Say i want to include the same chunck of text (a menu on a webpage for > > example) on each page. Is there a method by which I can save the HTML in > > a text file and call it up later? Is there a better way? > > > > > > I know ruby has "puts" but i can''t use that b/c it does not work with my > > > > webhost (dreamhost.com) > > > > Any suggestions? > > > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > Another alternative to this is to use the content_for method > > In you view > > <% content_for( "menu") do %> > erb for menu here > <% end %> > > and then in your layout > > <%= yield :menu %> > > This should put your menu code in. If it''s not right I''ll check then > syntax when I get home > > Cheers >I probably should add that this method is only really useful when the menu changes per view. Otherwise as others have suggested, stick it in the layout or a partial. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060725/bef7a3e8/attachment.html