The :new view when redirected if validations are not matched and where I'd like to see the error messages:
<%= simple_form_for ([ @recipe, @recipe.comments.build]), class:"comment-form" do |f| %>
<%= f.error_notification %>
<%= f.object.errors.full_messages.join(", ") if f.object.errors.any? %>
<%= f.input :name, label: false, placeholder: "Your name", input_html: { value: @comment.name } %>
<%= f.input :comment, label: false, placeholder: "Tell us about your experience", input_html: { value: @comment.comment } %>
<%= f.submit "Submit", class: "btn-comment-submit" %>
<% end %>
This is my controller:
def new
@recipe = Recipe.find(params[:recipe_id])
@comment = Comment.new
@comment = @recipe.comments.build
end
def create
@comment = Comment.new(comment_params)
@recipe = Recipe.find(params[:recipe_id])
@comment.recipe = @recipe
if @comment.save
redirect_to recipe_path(@recipe)
else
render :new
end
end
question from:https://stackoverflow.com/questions/65945225/why-does-simple-form-not-show-validation-error-messages-in-rails