Using render functions in my own classes


#1

Hello!

I’m trying to create my own Form handler as a replacement of the default
scaffolding. Creating HTML forms has never been my favorite job.

What I have done:

  • Created a new module FormHandler
  • Added a class Form in the module
  • Defined an initialize and to_s method. The initialize method receives
    some basic information about the form, the to_s method returns a string
    which contains the complete form.

The module wil be extended with FormElement classes, but I’m trying to
solve the following. In the to_s method, I would like to use
render_to_string :partial to render a template and return it as a
string. I managed to do this by extending ApplicationController::Base
and calling the function. The problem is that the method relies on the
contract that a request and response object are available.

Passing the response and request from the ApplicationController that
uses the FormHandler is an oppertunity, but is not very clean.

Is there any possibility to use the render functions of Rails without
the need to extend the Base class and the existens of the reponse en
request objects.

Thanks!

Edwin