This is not the best way to do this. replace @position with something more general, like "obj" (as an example) in your first block of code. So it will look.
<% if obj.errors.any? %> <div id="error_explanation"> <div class="alert alert-error"> The form contains <%= pluralize(obj.errors.count, "error") %>. </div> <ul> <% obj.errors.full_messages.each do |msg| %> <li>* <%= msg %></li> <% end %> </ul> </div> <% end %>
All you have done has replaced @position with obj. Now take the above code and put it in your shared folder as '_error_messages.html.erb'
Now for each file where you need error messages, you can display partial and replace obj with any instance variable in this file. (at this moment you will replace any error message code in your files with the code below, depending on the instance variable you are using. examples below) in the provisions:
<%= render 'shared/error_messages', obj: @position %>
at the user:
<%= render 'shared/error_messages', obj: @user %>
in the client:
<%= render 'shared/error_messages', obj: @client %>
etc .... obj: @client # or any instance variable disables the partial obj and puts the instance variable in it. Hope this helps!
source share