I have a similar issue, I believe, and tackled it this way:

1. Created a form helper:
def form_simplefield(f, label, field, opts={} )
  # ls & fs options define the label/field span amounts
  opts[:ls] ||= 8
  opts[:fs] ||= 16
  opts[:last] = opts[:last] ? 'last' : ''
  opts[:size] ||= nil
  opts[:as] ||= nil
  render 'shared/form_simplefield', :f => f, :form_field =>
field, :form_label => label,
          :lspan => opts[:ls], :fspan => opts[:fs], :last =>
opts[:last],
          :size => opts[:size], :as => opts[:as]
end

2. Created a matching partial
- form_field_sym = form_field.to_sym
%span{:class => "span-#{lspan}"}
  = f.label form_field_sym, form_label.tr("_"," ") + ":", :class =>
'form_label'
%span{:class => "span-#{fspan} #{last}"}
  - if as.blank? then
    = f.input form_field_sym, :label => false, :input_html => { :class
=> "form_field", :size => size }
  -else
    -#= f.input "#{form_field.to_sym}", :as =>
"#{field_as.to_sym}", :label => false, :input_html => { :class =>
"form_field", :size => size }
    -#= f.input form_field_sym, :as => "#{field_as.to_sym}", :label =>
false, :input_html => { :class => "form_field", :size => size }
    = f.input form_field_sym, :as => "#{as.to_sym}", :label =>
false, :input_html => { :class => "form_field", :size => size }

It's butt-ugly, but it works... mostly.  I've learned that using
simple_form with blueprint CSS causes some styling problems and I'm
working on that.  I'm also looking into ways to generate the code
directly from the helper without the partial.

HTH...jon

On Jul 5, 12:09 pm, Ryan Lundie <rlun...@gmail.com> wrote:
> Hi,
>
> I am in the process of creating a site what will allow the user to
> generate a form with whatever questions they would like to ask their
> users. I allow the user to create a form, add questions and choose
> various options for each one of the questions. I then save these
> options as a serialized hash in the database so that I can generate
> their form from the options they have chosen.
>
> In my new form view i then loop over this hash creating form fields
> for each field I have stored in the hash. I am currently using the
> eval method for each field so that I can create a string of the field
> options, and then have ruby evaluate that into usable code. Here is an
> example:
>
> (I am using HAML and the simple_form gem)
> = eval("#{field['form_name']}.input :#{field['field_name']}, :label =>
> '#{field['wording'][I18n.locale.to_s]}', :hint => '#{field['hint']
> [I18n.locale.to_s]}', :required => (#{field['required']} == 1)" ) if
> field['display'] == 1
>
> I am running into with using eval and Haml is when I am creating a
> fields_for section and using eval to do so:
> eval("#{field['form_name']}.simple_fields_for :#{field['association_name']}
> do |#{field['association_name']}|")'
>
> I think that Haml does not recognize this as ruby syntax and therefor
> does not automatically close off any of the tags (from what I can
> gather).
>
> Any help is appreciated!
>
> Ryan

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to haml@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Reply via email to