How to generate dynamic javascript files with Ruby on Rails?

The problem

I want to write JavaScript files that use dynamic informations via Ruby on Rails. I think my solution also works with rails 2 and 3.
What can dynamic JavaScript do for you? You can write JavaScript on your ERB (embedded ruby) file beside HTML code. This is very simple, but not the best solution for a longer jQuery script.
For example:
Translation in JavaScript: translation with I18n.t() Rails method would be great in separated JavaScript file with ERB capability.

// some jquery code before alert