# before\_validation coding help

**URL:** <https://discuss.rubyonrails.org/t/before-validation-coding-help/57309>\
**Category:** rubyonrails-talk\
**Created:** [February 13, 2011, 9:26pm UTC](https://discuss.rubyonrails.org/t/before-validation-coding-help/57309 "2011-02-13T21:26:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shirl\_Hart](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Shirl\_Hart](https://discuss.rubyonrails.org/u/Shirl_Hart)\
**Post date:** [February 13, 2011, 9:26pm UTC](https://discuss.rubyonrails.org/t/before-validation-coding-help/57309/1 "2011-02-13T21:26:07Z")

</div>

I can't get both of these validations to work, I must comment out one or the other.

&nbsp;&nbsp;before\_validation :amazon\_ecs\_lookup\_item, :on =\> :create &nbsp;&nbsp;before\_validation :amazon\_ecs\_lookup\_item, :on =\> :update, :if =\> :refresh

in this case only update works

&nbsp;&nbsp;before\_validation :amazon\_ecs\_lookup\_item, :on =\> :create # before\_validation :amazon\_ecs\_lookup\_item, :on =\> :update, :if =\> :refresh

now create works

I guess you can only code 1 so how do you code it?

&nbsp;&nbsp;before\_validation :amazon\_ecs\_lookup\_item, [:on =\> :create, {:on =\> :update, :if =\> :refresh}]

doesn't work.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Jim\_Ruther\_Nill](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@Jim\_Ruther\_Nill](https://discuss.rubyonrails.org/u/Jim_Ruther_Nill)\
**Post date:** [February 14, 2011, 8:58am UTC](https://discuss.rubyonrails.org/t/before-validation-coding-help/57309/2 "2011-02-14T08:58:29Z")

</div>

I think wrap your amazon\_ecs\_lookup\_item with

if new\_record? or refresh

…

end

---

<div class="post-metadata">

**Author:** ![Shirl\_Hart](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Shirl\_Hart](https://discuss.rubyonrails.org/u/Shirl_Hart)\
**Post date:** [February 14, 2011, 7:29pm UTC](https://discuss.rubyonrails.org/t/before-validation-coding-help/57309/3 "2011-02-14T19:29:29Z")

</div>

Thanks. That makes sense.
