dynamically generating form tags

i'm trying to create a form which has dropdown menus for certain items and text boxes for others. i have a feeling i'm trying way too hard to make this happen. i have a method which writes strings of the proper tags, which are then brought to life by eval() in the view. the strings are correct, but something about how eval parses the string only allows for one argument, even if i parenthesize them. i feel like i should not have to be using eval at all.

any guidance is appreciated.

THE CONTROLLER:

  def run     @script = @@scriptinfo.getTest(params[:choose][:scriptname])     @parameterforms = @script.parameters.collect { |param| chooseForm(param) }   end

  def chooseForm(parameter)     if parameter.length <= 1       "f.text_field :#{parameter.name}"     else       "f.select :#{parameter.name}, #{parameter.values.join(', ')}] "     end   end

THE RUN VIEW:

<% form_for :scriptparams, :url => {:action => "results"} do |f| %> <% @script.parameters.each_index do |index| %>   <%= @script.parameters[index].name %>   <%= eval(@parameterforms[index]) %><br />   <% end %> <% end %>

would returning a lambda object work?

Reid Oda wrote:

i'm trying to create a form which has dropdown menus for certain items and text boxes for others. i have a feeling i'm trying way too hard to make this happen. i have a method which writes strings of the proper tags, which are then brought to life by eval() in the view. the strings are correct, but something about how eval parses the string only allows for one argument, even if i parenthesize them. i feel like i should not have to be using eval at all.

Put the view related code into the view instead of the controller:

Controller:

def run   @script = @@scriptinfo.getTest(params[:choose][:scriptname]) end

View:

<% form_for :scriptparams, :url => {:action => "results"} do |f| %>   <% @script.parameters.each do |param| %>     <% if param.values -%>       <%= f.select param.name, param.values %>     <% else -%>       <%= f.text_field param.name %>     <% end -%>     <br/>   <% end %> <% end %>

If you do this in more than one place, then you can factor it out into a helper...