Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

FoundationFormbuilder built in ODOT course does not work with select form tag

Hi, I did ODOT app and Im making some custom things there, I want to add aselect while creating the todo list that will be something similar to a category, but it seems the FoundationFormBuilder that jason did does not work with selects

this is what I have in the form builder

%w(select email_field text_field password_field).each do |form_method|
        define_method(form_method) do |*args|
            attribute = args[0]
            options = args[1] || {}
            options[:label] ||= attribute.to_s.titleize
            label_text ||= options.delete(:label)
            label_options ||= {}
            if errors_on?(attribute)
                wrapper_options = { wrapper_classes: "error"}
            end
            wrapper(wrapper_options) do
                label(attribute, label_text, label_options) +
                super(attribute, options) + errors_for_field(attribute)
            end         
        end
    end

I added the select in the %w array but it just does not work, I get syntax error, I want to be able to build a select list like:

<%= f.select :status, label: 'Status', [['Pendiente', 'pendiente']] %>

What do I need to add to the form builder in order to acept selects?

thanks for your help

1 Answer

Hey Sebastian,

I don't know how to correctly add a select in your %w array with the Foundation FormBuilder. However, if you're getting a syntax error I'd look at the code for the select element in your view:

<%= f.select :status, label: 'Status', [['Pendiente', 'pendiente']] %>

You've got an array inside an array, but there are no other values alongside the nested array, which doesn't seem right. Maybe try just ['Pendiente', 'pendiente'] ?

I hope that helps :D

well I saw in rails documentation and the array should be like it is, [[machine_value, human_readable_avlue]]

That's why, thanks anyway