Validation error not showing up in browser
articles controller
class ArticlesController < ApplicationController
def show
@article = Article.find(params[:id])
end
def index
@articles = Article.all
end
def new
@article = Article.new
end
def create
@article = Article.new(params.require(:article).permit(:title, :description))
if @article.save
redirect_to @article
else
render 'new'
end
end
end
new.html.erb
Create a new article
<% if @article.errors.any? %>
The following errors prevented the article from being saved
- <%= msg %>
<% @article.errors.full_messages.each do |msg| %>
<% end %>
<% end %>
<%= form_with scope: :article, url: articles_path, local: true do |f|%>
<p>
<%= f.label :title%><br>
<%= f.text_field :title%>
</p>
<p>
<%= f.label :description%><br>
<%= f.text_area :description%>
</p>
<p>
<%= f.submit%>
</p>
<% end %>