# Exception is not raise with #t method on Rails 2.3.5

**URL:** <https://www.ruby-forum.com/t/exception-is-not-raise-with-t-method-on-rails-2-3-5/191424>\
**Category:** Rails I18n\
**Created:** [July 12, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/exception-is-not-raise-with-t-method-on-rails-2-3-5/191424 "2010-07-12T14:43:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MickaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MickaSSSSl](https://www.ruby-forum.com/u/MickaSSSSl)\
**Post date:** [July 12, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/exception-is-not-raise-with-t-method-on-rails-2-3-5/191424/1 "2010-07-12T14:43:26Z")

</div>

Hi folks,

I have read some documentation about I18n and exceptions, but I need  
your help.

My idea is to implement an exception when my functional test watch a  
missing translation like what I’m seeing in “Rails  
Internationalization (I18n) API Guide” ([http://guides.rubyonrails.org/](http://guides.rubyonrails.org/)  
i18n.html#using-different-exception-handlers). The documentation seem  
to be old.

I try some context.

Gist number 1 ([gist:472395 · GitHub](http://gist.github.com/472395)) works with #t method and  
a correct translation key.

Gist number 2 ([OUTPUT · GitHub](http://gist.github.com/472404)) doesn’t raise an  
exception with #t method.

Gist number 3 ([OUTPUT · GitHub](http://gist.github.com/472423)) raise an exception but I  
must specify I18n.t method to translate.

Questions are :

How to implement a raise with #t helper method ?  
And, how to specify the right exception ?

Thank’s for your patience and your help.

Best regards,

Mickaël.

---

<div class="post-metadata">

**Author:** ![MickaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MickaSSSSl](https://www.ruby-forum.com/u/MickaSSSSl)\
**Post date:** [July 12, 2010, 2:56pm UTC](https://www.ruby-forum.com/t/exception-is-not-raise-with-t-method-on-rails-2-3-5/191424/2 "2010-07-12T14:56:20Z")

</div>

Hi!

Unfortunately, you cannot raise in your views, because the default  
view helpers will always rescue the exception:

[http://github.com/rails/rails/blob/master/actionpack/lib/action\_view/helpers/translation\_helper.rb#L33](http://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/translation_helper.rb#L33)

t/translate as defined in the views is not just a shortcut/alias to  
I18n.t, but does a lot of stuff around it.

Either redefine this method in your own helper or use I18n.t if you  
don’t want it. There seems to be no other way.

Iain

---

<div class="post-metadata">

**Author:** ![MickaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MickaSSSSl](https://www.ruby-forum.com/u/MickaSSSSl)\
**Post date:** [July 12, 2010, 3:42pm UTC](https://www.ruby-forum.com/t/exception-is-not-raise-with-t-method-on-rails-2-3-5/191424/3 "2010-07-12T15:42:35Z")

</div>

Thank’s for you response Iain.

I want to raise an exception only in test environnement, so, I prefer  
to use my own helper method.  
So in my test\_helper.rb, I add some hack in #translate method from  
module TranslationHelper like in [test\_helper.rb · GitHub](http://gist.github.com/472463)

In my view I have #t method to call translation but they didn’t raise  
exception too.

Why my #translate method doesn’t raise exception ?

Best regards,

Mickaël.

You are right, view helpers will always rescue the exception and

---

<div class="post-metadata">

**Author:** ![MickaSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MickaSSSSl](https://www.ruby-forum.com/u/MickaSSSSl)\
**Post date:** [July 12, 2010, 5:36pm UTC](https://www.ruby-forum.com/t/exception-is-not-raise-with-t-method-on-rails-2-3-5/191424/4 "2010-07-12T17:36:46Z")

</div>

After some attempts, here we go 😉

My mistake was to retrieve code directly from Iain’s links  
[http://github.com/rails/rails/blob/master/actionpack/lib/action\_view/helpers/translation\_helper.rb#L33](http://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/translation_helper.rb#L33)  
but my rails app run in 2.3.5 … so, check the right tag in Github  
before past it into test\_helper.rb…

Solution for Rails 2.3.5 could be found here :

> <https://gist.github.com/mallain/472582>

Thank’s again Iain.

Best regards,

Mickaël.
