# Custom validation and i18n

**URL:** <https://www.ruby-forum.com/t/custom-validation-and-i18n/164459>\
**Category:** Rails\
**Created:** [April 1, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/custom-validation-and-i18n/164459 "2009-04-01T17:07:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasmus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@rasmus](https://www.ruby-forum.com/u/rasmus)\
**Post date:** [April 1, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/custom-validation-and-i18n/164459/1 "2009-04-01T17:07:06Z")

</div>

Hi guys,

I’m looking for some advice on how to follow best practices. In my app  
users can create “reports”. A report belongs to an employee.

Therefore, when creating a report I want to check, that the chosen  
employee actually exists and that the user are allowed to use this  
employee. To do this, I’ve made a custom validation method (in the  
report model), that checks whether the employee exists or not and  
whether the user can use this employee. If something’s wrong, it call  
errors.add\_to\_base “some text”. The problem is, that “some text” needs  
to be translated according to what user is viewing the page. So  
essentially, the model needs to have access to both action view methods  
as well as the session (in order to determine current language). This is  
afaik very bad practice (to give the model this access).

Another solution would be to call @report.errors\_add\_to\_base from the  
controller - however, that would break the idea of “thin controllers,  
fat models”. Also, it will lead to ugly such as

@report.errors.add\_to\_base t(:error\_msg) if something\_wrong?

if @report.validates? && save # (save seems to clear errors, so I need  
to call validates before save)

# succes

else

# show error page

end

So, dear fellow rails users, what do you think of this problem? What  
would you do here? Any advice very appreciated, thanks.
