Ruby on Rails Sunday, January 29, 2012

Hi,

I am trying to create a custom form builder but got the following error: wrong argument type Class (expected Module)

To create a form builder I have to subclass ActionView::Helpers::FormBuilder. So, I guess, it must be a class and not a module or maybe a class wrapped inside a module....

Here is the idea:

The helper (/app/helpers/custom_form_helper.rb):

class CustomFormHelper < ActionView::Helpers::FormBuilder

    def datalist_for(method, choices, options = {})
     ...     # I'd like to render a partial here with :locals => {:list => choices, :name => @object_name + "[_#{method}]"}
    end
end

The partial (app/view/shared):

 <input type="text" name=<%= name %> list="list">
  <datalist id="list">
    <% choices.each do |elem| %>
        <option value=<%= elem %> >
    <% end %>
  </datalist>

The view:

<%= form_for(:moove, :builder => "CustomFormHelper" :url => {:action => 'create'}) do |f| %>
    <table>
        <tr>
            <td><%= f.datalist_for(:sport, @sports)%></td>
        </tr>
    </table>
<% end %>

Thank you in advance for your help,

Alexandre

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment