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.
> 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
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")) %> Mischa Berger wrote:>> 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
> 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")) %>