Search code examples
ruby-on-railsrubyruby-on-rails-4rubymine-7

Use template to create multi-page ruby on rails web application


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.


Solution

  • 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. :)