I am trying to capture validation errors for individual forms as I have many on one page.
I am giving each form its own unique id by using object_id
<% object = @document || Document.new %>
<%= form_for object, :html => { id: object.object_id.to_s } do |f| %>
But if i do this to capture errors the same error message will appear on all my forms
<% if object.errors.any? %>
# errors
<% end %>
I have tried
<% if object.object_id.errors.any? %>
But i get
undefined method `errors' for 59187740:Fixnum
Is there a way around this please
Thanks
Edit
i have just noticed that the form id changes when validation fails as the page reloads, so that explains why the object cannot be found.
How can i keep the form id the same?