# Question about validate

**URL:** <https://www.ruby-forum.com/t/question-about-validate/47712>\
**Category:** Rails\
**Created:** [November 12, 2005, 1:42pm UTC](https://www.ruby-forum.com/t/question-about-validate/47712 "2005-11-12T13:42:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spmm\_pls](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@spmm\_pls](https://www.ruby-forum.com/u/spmm_pls)\
**Post date:** [November 12, 2005, 1:42pm UTC](https://www.ruby-forum.com/t/question-about-validate/47712/1 "2005-11-12T13:42:33Z")

</div>

Hi,

I have this class called Myfile (cause file is a reserved word), when a  
validation of a field in this class fails the error message shows: “1  
error prohibited this myfile from being saved”, of course I just want it  
to say file instead of myfile. However… I don’t have a clue how to do  
this.

Any ideas???

Thanks,  
Mischa.

---

<div class="post-metadata">

**Author:** ![spmm\_pls](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@spmm\_pls](https://www.ruby-forum.com/u/spmm_pls)\
**Post date:** [November 12, 2005, 5:20pm UTC](https://www.ruby-forum.com/t/question-about-validate/47712/2 "2005-11-12T17:20:07Z")

</div>

> I have this class called Myfile (cause file is a reserved word), when a  
> validation of a field in this class fails the error message shows: “1  
> error prohibited this myfile from being saved”, of course I just want it  
> to say file instead of myfile.

OK, I’m getting around it like this now:

\<% err = error\_messages\_for(“myfile”) %\>  
\<% if err %\>  
\<%= err.sub!(“myfile”, “file”) %\>  
\<% end %\>

But there must be any another way. Help!

Grt,  
Mischa

---

<div class="post-metadata">

**Author:** ![spmm\_pls](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@spmm\_pls](https://www.ruby-forum.com/u/spmm_pls)\
**Post date:** [November 12, 2005, 8:48pm UTC](https://www.ruby-forum.com/t/question-about-validate/47712/3 "2005-11-12T20:48:35Z")

</div>

another (shorter) way:  
\<% err = ((a=error\_messages\_for(“myfile”)).nil? ? nil : a.sub(“myfile”,  
“file”)) %\>

better yet, you could create a new function in a helper to perform the  
transform:

def myfile2file(s)  
return if s.blank?  
s.sub “myfile”, “file”  
end

\<% err = myfile2file(error\_messages\_for(“myfile”)) %\>

---

<div class="post-metadata">

**Author:** ![spmm\_pls](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@spmm\_pls](https://www.ruby-forum.com/u/spmm_pls)\
**Post date:** [November 12, 2005, 10:58pm UTC](https://www.ruby-forum.com/t/question-about-validate/47712/4 "2005-11-12T22:58:30Z")

</div>

> def myfile2file(s)  
> return if s.blank?  
> s.sub “myfile”, “file”  
> end
> 
> \<% err = myfile2file(error\_messages\_for(“myfile”)) %\>

Thanks. Why didn’t think of that myself? In the end I implemented it  
like this:

def myfile\_to\_file(msg)  
msg.sub(“myfile”, “file”) if msg  
end

\<%= myfile\_to\_file(error\_messages\_for(“myfile”)) %\>
