views:

610

answers:

0

I'm looking for some advice on designing the above for a RoR application that basically has two sections:

1) Admin Form Builder 2) End User Form (that was created by the admin in step 1)

I've prototyped the JQuery form (end result) I want and it uses "progressive disclosure" (similar to Yehuda Katz's Bamboo example in the JQuery in Action book), so if you click one item another item might open (eg click the "registration checkbox" and another registration sub-form is displayed). I also have the rails application actually building a couple of inputs as described. However, I feel like I'm not really utilizing the dynamic capabilities of Ruby. For example, here's a slice of one of my module methods that builds a particular simple html input:

module Levin 
  module EventReg 
    module Jquery

  def self.simple_registration_text(input_params)
    raise ArgumentError if input_params.nil?
    ip_id = input_params[:input_div_id] 
    simple_reg_input_html = '<p><label for="'
    simple_reg_input_html << "#{ip_id + '_label_id'}\">"
    ........<A BUNCH MORE CODE TO BUILD INPUT>........
    simple_reg_input_html << ' class="required"' unless input_params[:is_required].eql?("0")    
    simple_reg_input_html << '/></p>'
  end

Basically, the administrator can name the input item and I use that for the div id's, etc. Given that I have many input types (select drop downs, textareas, inputs with children like an input type text with a checkbox that, when checked, opens a data grid, that can add/remove items via a dialog popup form, etc.), I'd like to avoid "hard-wiring" build methods like in my example above. Also, it would be great to allow the caller to be responsible for BOTH the input value choices (which is already happening when they pass input params parameter), and ALSO the builder itself.

I'm very new to functional programming but I'm thinking of something to the affect of the caller passing in a "builder" lambda that builds the specific form input they need using the input params leading to:

builder_lambda.call(input_params)

But when I think about this, it seems the lambda will look very similar to what the Jquery module is already doing. Yes, the caller will have the ability to create a custom builder to their liking, but then what is my module method gonna really do! What value will it provide?

I will also sometimes need to connect these inputs to specific event handlers. Perhaps there could be an array of lamdas, a builder and an add event handler like:

builder_lambda.call(input_params)

add_event_handlers_lambda.call(input_params)

Am I on the right track? Sorry if I'm rambling on, but I'm obviously having trouble decomposing this problem into a "Ruby-istic" solution and ideas for a more dynamic approach would be greatly appreciated.

EDIT: This was helpful for me: Obie Fernandez DSL Development PDF