# Best way to develop a self-contained widget?

**URL:** <https://www.ruby-forum.com/t/best-way-to-develop-a-self-contained-widget/91543>\
**Category:** Rails\
**Created:** [April 10, 2007, 9:07am UTC](https://www.ruby-forum.com/t/best-way-to-develop-a-self-contained-widget/91543 "2007-04-10T09:07:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@jug](https://www.ruby-forum.com/u/jug)\
**Post date:** [April 10, 2007, 9:07am UTC](https://www.ruby-forum.com/t/best-way-to-develop-a-self-contained-widget/91543/1 "2007-04-10T09:07:15Z")

</div>

Hello,

I am developing a small widget composed of several form elements, which  
are connected with javascript code (i.e. what the user does on an  
element has an impact on what another element shows).

At first I put the code in a function in my application helper, but as  
the widget was evolving, I wanted to put it in a dedicated class, as  
each instance of the widget needs some business logic. Indeed, sometimes  
the widget has to be placed several times on a page, and the UI items  
are not always beside each other (they could be on several rows of a  
table), so each widget should have several attributes (such as the DOM  
id of each of its elements) and several methods (e.g. to display each  
part of the widget as needed).

So I made a class in the /lib directory, containing all the code of the  
widget. This is elegant, but then I noticed that I cannot use ActionView  
helper functions (such as select\_tag or javascript\_tag) from within that  
class. I know that I could include all the needed ActionView::Helpers  
modules in the class, but is it really the best way to do that ? How  
would you develop such a reusable widget, composed of html elements,  
javascript and some ruby logic ?

Thanks in advance,

Nicolas
