How can I display errors using Rails form_with (remote form with Ajax) helper?
I have this code:
def create
@incoming_package = IncomingPackage.new(tracking: params[:tracking])
if @incoming_package.save
redirect_to admin_incoming_packages_path, notice: "created"
else
flash.now[:danger] = "error" # not displayed
end
end
Here is my form:
<%= form_with url: admin_incoming_packages_path do |form| %>
<%= form.text_field :tracking, required: true, autofocus: true, autocomplete: :off %>
<%= form.submit "Add" %>
<% end %>
If there is no errors rails-ujs + Turbolinks works fine and new package is automatically added on page. How can I display errors (or anything) if a package failed to save?
Here's a simple way to get you started:
On your form's view page:
Then on your
createaction do:You must also make sure your
newaction has: