So I'm trying to get the errors from my form that is rendered as a partial inside my root_path. After I attempt to post it, and it fails (or succeeds), I want to redirect back to the root_path. However, redirect_to decides to not save any information for the validation.
Wondering how to do this.
class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@nom = current_user.noms.build(params[:nom])
if @nom.save
flash[:success] = "Nom created!"
redirect_to root_path
else
flash[:error] = @nom.errors
redirect_to root_path
end
In my Home/Index, I render the partial for the form of the post.
= form_for [current_user, @post] do |f|
= f.text_field :name
= f.select :category
= f.text_area :description
= f.submit "Post", class: "btn btn-primary"
- @post.errors.full_messages.each do |msg|
%p
= msg
It should be keeping the errors at the bottom of the form after it redirects to the root_path.
I'd also like to keep the information that was there after the validation failed.