0

Is there any way to create a webpage template that I will be applying to all my webpages? I am new to ruby on rails, I have gained enough knowledge to understand how flow works in it but can't find out the way to use the same page-template for all pages on the site. I am using RubyMine but can work on command prompt if required.

Any help would be greatly appreciated.

cfrick
  • 35,203
  • 6
  • 56
  • 68
VD007
  • 267
  • 2
  • 15
  • Just foundout that in layout, I need to place <%= yield %> to render any webpage. Not sure if i am right. – VD007 Jun 05 '15 at 02:54
  • Yes that's correct you can use layout to use sample page template and include '<%= yield %>' page specific content – Anant Kolvankar Jun 05 '15 at 02:58
  • See here for things you can do: https://www.railstutorial.org/book/static_pages#sec-layouts_and_embedded_ruby ... and here: http://guides.rubyonrails.org/layouts_and_rendering.html – 7stud Jun 05 '15 at 03:32

2 Answers2

2

app/views/layout/application.html.erb this is a common layout in which you will found <%= yield %> which render all the pages in <body> tag. Now as per your requirement you want some common template to show on all pages.

So better to make one partial file..For example, Header and Footer remains same in whole site. For doing this, make one partial file called _header.html.erb for header part and _footer.html.erb for footer part. Put these files under app/views/layout/_your_partialfile.html.erb

Then render them like:

<%= render partial: "/layouts/header" %>
<%= yield %>
<%= render partial: "/layouts/footer" %>

For more info refer : http://guides.rubyonrails.org/layouts_and_rendering.html

I hope this makes you clear to understand now. :)

Gagan Gami
  • 10,121
  • 1
  • 29
  • 55
  • Thanks for the explanation. It was very helpful. But having another issue now. I am trying to render a form that is created with form_for, The page is not giving any error, however i can't see the form fields (i can see heading etc.). Do i need to import anything like how we do in java if you know?? – VD007 Jun 05 '15 at 15:21
  • @VD007 : Can you provide me some details like where you have made form's file with what name? And also let me know where and how you render it? – Gagan Gami Jun 08 '15 at 05:27
0

In general, rails projects have a file in app/layouts/application.html.haml that's applied to every single page you load. You can put navbars there, login links, etc.

Waynn Lue
  • 11,344
  • 8
  • 51
  • 76