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 %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
would returning a lambda object work? On Fri, Mar 21, 2008 at 2:04 PM, Reid Oda <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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. > > 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 %> > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---