customized form_for tag in rails
- by poseid
I want to make a table within a form by making a new form_tag. The following code in ApplicationHelper fails:
module ApplicationHelper
class TabularFormBuilder < ActionView::Helpers::FormBuilder
# ... code to insert <tr> tags </tr>
end
def tabular_form_for(name, object = nil, options = nil, &proc)
concat("<table>", proc.binding)
form_for(name,
object,
(options||{}).merge(:builder => TabularFormBuilder),
&proc)
concat("</table>", proc.binding)
end
end
The view I use is:
<h1>New project</h1>
<% tabular_form_for :project, :builder => ApplicationHelper::TabularFormBuilder do |f| %>
<%= f.error_messages %>
<%= f.text_field :name %>
<%= f.text_area :description %>
<%= f.text_field :location %>
<%= f.submit 'Create' %>
<% end %>
The error I get is:
NoMethodError in Projects#new
Showing app/views/projects/new.html.erb where line #5 raised:
undefined method `errors' for {:builder=ApplicationHelper::TabularFormBuilder}:Hash
Any ideas how to make this custom tag work?