Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get at the underlying object inside a Rails form or field_for block?

I can't figure-out how to get at the underlying object in a form_for or field_for block.

What I'd like to do is something like:

<% f.fields_for :children do |child_form| %>
  <%= render :partial => "#{child_form.underlying_object.class.name.downcase}" %>
<% end %>

and :children is a polymorphic has_many association.

Suggestions?

like image 234
Mike Summers Avatar asked Oct 12 '09 19:10

Mike Summers


1 Answers

Isn't it just

<% f.fields_for :children do |child_form| %>
<%= render :partial => "#{child_form.object.class.name.downcase}" %>
<% end %>
like image 151
Damian Avatar answered Sep 22 '22 13:09

Damian