Note that there are some explanatory texts on larger screens.

plurals
  1. POerror_message partial not rendered in Rails
    primarykey
    data
    text
    <p>I have problems displaying <code>error_messages.html.erb</code> partial when building custom validation.</p> <p>I have for instance, a form to make a transaction, which starts like:</p> <pre><code>&lt;%= form_for @transaction do |f| %&gt; &lt;%= render 'shared/error_messages', :object =&gt; f.object %&gt; </code></pre> <p>I have a validation which prevents a user from making a transaction with himself:</p> <pre><code>validate :self_transaction_not_possible </code></pre> <p>with</p> <pre><code> def self_transaction_not_possible bel = Belonging.find_by_id(self.belonging.id) unless bel.nil? if self.user_id == bel.user_id errors.add(:base, "You cannot perform a transaction with yourself") end end end </code></pre> <p>Then I ran such an example in the browser (initiate a transaction on a belonging I own), and I placed a debugger inside self_transaction_not_possible. I checked that the validation happens, and indeed, inside the debugger, I see that typing: self.errors.full_messages give me my error message, so validation seems to be performed...</p> <p>I would then have expected, as the object was not valid, that the error message would appear in my view, but no ... putting the debugger inside the <code>error_messages.html.erb</code> partial showed me that object.errors.any remains == {} :-/ ... </p> <p>The user is then redirected towards the page it should see when the saving process fails (validation has been performed correctly), but he never sees the error message ... </p> <p>Am I missing something obvious ? ... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload