I'm currently working on Ruby on Rails Getting Started page. I have done 5.10 so far.
At 5.10, adding validation, there are the title field and the text area in the "New Article" page. When the "save article" button is clicked, title field is validated, and if it is blank or too short, error is thrown, and the error message is rendered in the page.
The problem I have is when error message is rendered, the title field gets an extra blank space between "Title" label and its text field.
The cause is probably div block's default behavior, as described in this question.
Before error:
<label for="article_title">Title</label>
After error:
<div class="field_with_errors">
<label for="article_title">Title</label>
</div>
So, I want to edit css for only this "New Article" page, to remove an extra blank space. But I have no idea how to do that. Probably The change to css that I need to add is the following:
div.field_with_errors {
display: inline;
}
Do I need to add some code to the erb file, or create a css file for this page?
The following is code in app/views/articles/new.html.erb.
<h1>New Article</h1>
<%= form_for :article, url: articles_path do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@article.errors.count, "error") %>
prohibited this article from being saved:
</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<%= link_to 'Back', articles_path %>

