Using rails 4.1, I am rendering a contact partial on my root => pages#home. Upon failing the create action, it renders contacts/new. And upon success will render create.
What is the best way to render the current root path with validations? I'd like to keep everything within the same view, if error or success. I have found similar answers, many on rails 3 or prior. Nothing seemed to work.
Partial View
<%= simple_form_for @contact, :html => {:class => 'form-horizontal col-sm-12'} do |f| %>
Controller
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(params[:contact])
@contact.request = request
if @contact.deliver
flash.now[:notice] = 'Thank you for your message. We will contact you soon!'
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
end
simple_formprovides lots of nice functionality to do this for you. - Adam Waite