-1

I have a scaffold generated index.html.erb and am wondering if it is okay that is does not have basic HTML structure?

This is my code:

<% provide(:title, "Signing Up") %>
<h1>Signing Up</h1>

<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(:reader, url: readers_path) do |f| %>
        <%= f.label :email %><br>
        <%= f.email_field :email, class: 'form-control' %>
      </p>
      <p>
        <%= f.label :password %><br>
        <%= f.password_field :password_digest, class: 'form-control' %>
      </p>
      <%= f.submit "Signing Up", class: "btn btn-primary" %>
    <% end %>

  </div>
</div>

I don't see usual HTML, <body>, <head> tags etc. Can I add it or is it not necessary?

Luka Kerr
  • 4,161
  • 7
  • 39
  • 50

1 Answers1

6

It isn't necessary. In Rails, you have an application.html.erb file under views/layouts. This is used as a default for rendering any page.

This file is where you will see the usual HTML structure (DOCTYPE, head, body etc).

To find the base layout, Rails will look for a file in app/views/layouts with the same base name as the controller.

For example, rendering actions from the PostsController class will use app/views/layouts/posts.html.erb.

If there is no such controller-specific layout, Rails will use app/views/layouts/application.html.erb which is what is happening when you generate the scaffold.

This is what the application.html.erb looks like generally on a fresh project:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %> #Content from the views is shown

</body>
</html>

See the docs for more information

Luka Kerr
  • 4,161
  • 7
  • 39
  • 50