<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Running validations without @errors]]></title>
		<link>http://railsforum.com/viewtopic.php?id=50580</link>
		<description><![CDATA[The most recent posts in Running validations without @errors.]]></description>
		<lastBuildDate>Wed, 03 Oct 2012 01:16:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Running validations without @errors]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=155826#p155826</link>
			<description><![CDATA[<p>Hi all,<br />&nbsp; &nbsp;I&#039;m refactoring a bit of code in my application that handles data integrity. Basically, I have methods like user.step1_completed? and user.step2_completed? that are just conditional statements returning true or false. Since I already have my validations set up, I want to DRY up the logic by simply running the validations and returning true or false (like user.valid?). For example, this is what I&#039;ve done (which works with the exception of nested attributes) Note that I&#039;m using a custom validator that I made which just specifies which validations to run:</p><div class="codebox"><pre><code>def step1_completed?
  mock = self.dup
  mock.validated_fields = [ :first_name, :middle_name, :last_name, :email, :street_address, :city, :state_str, :zip_code, :birth_date, :currently_insured ]
  validity = mock.valid?
  self.valid? if original_errors_count &gt; 0  #because self.errors gets cleared when running mock.valid?
  return validity
end</code></pre></div><br /><p>The problem is context -- I use these methods in my views, and doing so can alter the @errors, which can really screw up the error messages shown on the page.</p><p>Thus, my question is: Is it possible to run all validations on a particular model WITHOUT modifying @errors? Looking at the source, I&#039;m not sure if it is. But there must be some way to do this.</p><p>Thanks in advance,</p>]]></description>
			<author><![CDATA[dummy@example.com (ibanez270dx)]]></author>
			<pubDate>Wed, 03 Oct 2012 01:16:20 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=155826#p155826</guid>
		</item>
	</channel>
</rss>
