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?
If you want to check any errors ruby give a very easy way to do it
@incoming_packages.errors.full_messages
will show all errors related to your model. also you can interact with all these errors