# using view helpers in JavaScript templates

**URL:** <https://discuss.rubyonrails.org/t/using-view-helpers-in-javascript-templates/62823>\
**Category:** rubyonrails-talk\
**Created:** [February 15, 2012, 1:24am UTC](https://discuss.rubyonrails.org/t/using-view-helpers-in-javascript-templates/62823 "2012-02-15T01:24:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liam](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@Liam](https://discuss.rubyonrails.org/u/Liam)\
**Post date:** [February 15, 2012, 1:24am UTC](https://discuss.rubyonrails.org/t/using-view-helpers-in-javascript-templates/62823/1 "2012-02-15T01:24:56Z")

</div>

I'd like to use ERB in my JS templates. Sometimes I want \<%= image\_tag %\>, other times I might want something more serious/non-assety like \< %= form\_for %\>. (There was an issue for Sprockets to allow for ActionView to be used in the asset pipeline so that that could work: [https://github.com/sstephenson/sprockets/issues/218](https://github.com/sstephenson/sprockets/issues/218), but it turns out it's not so simple.)

I guess there are a few ways that I could do this, so I'm looking for a best practice. How do you handle view helpers, like form\_for? Do you render your template within the view, or do you just use old school pure html, or are there any bridge approaches?

Right now we're trying out codebrew's backbone-rails gem, but we definitely need to find a migration path for the extensive system of view helpers both in Rails and in our own project that we'd like to reference.
