customized form_for tag in rails
Posted
by poseid
on Stack Overflow
See other posts from Stack Overflow
or by poseid
Published on 2010-05-19T08:02:40Z
Indexed on
2010/05/19
20:00 UTC
Read the original article
Hit count: 166
ruby-on-rails
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?
© Stack Overflow or respective owner