Templates

A Rails template is a text document or Python string marked using the Rails template language. Some builds are recognized and interpreted by the template engine. The main ones are variables and tags. Templates are provided with context. Rendering replaces a variable with its value, which is searched in context and executes a tag. Everything is output as is.

Base Template

For each controller, there is an associated directory in the app/views directory which holds the template files that make up the views associated with that controller. These files are used to display the view that results from each controller action.
rails generate scaffold article
This command will help you with the creation of required files to build CRUD.
Open the file app/controllers/article_controller.rb and put the following Ruby code in it:
class ArticlesController < ApplicationController
  def initialize
    super
    # Include the main layout bootstrap file
    require_relative "../views/#{Rails.configuration.settings.KT_THEME_LAYOUT_DIR}/_bootstrap/default"

    # Initialize the main layout bootstrap class
    KTBootstrapDefault.new.init(helpers)
  end
end
Find the file app/views/pages/articles/index.html.erb. For each view file, this is the basic template you need. render template function will make use of the Metronic layout from app/views/layout
<% content_for :layout do %>

Article content

<% end %>

<%= render template: "#{Rails.configuration.settings.KT_THEME_LAYOUT_DIR}/default" %>
Add the page route into config/routes.rb file.

Layout Partials

Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file. To render a partial as part of a view, you use the render method within the view:
<%= render 'drawers' %>
This will render a file named _drawers.html.erb at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:
<%= render 'partials/drawers' %>
That code will pull in the partial from app/views/partials/_drawers.html.erb.

Pages

This is a minimal page file to import with the base layout file. For each page file, the main layout is required and need to be called via render template function. The config here #{Rails.configuration.settings.KT_THEME_LAYOUT_DIR} is referred to the settings file config/settings.yml
<% content_for :layout do %>
            
    Content here

<% end %>

<%= render template: "#{Rails.configuration.settings.KT_THEME_LAYOUT_DIR}/default" %>
There are 4 main layouts available:
  • app/views/layout/auth.html.erb
  • app/views/layout/default.html.erb
  • app/views/layout/default_header_layout.html.erb
  • app/views/layout/system.html.erb
For example:
<%= render template: "layout/default" %>
Preview Get Help Buy Now