views:

26

answers:

1

Stuck trying to figure out how this nested form should work. Right now, it's not displaying the embedded text_area (g.text_area), but I don't see why. Any help would be much apprecaited!

class Channel < ActiveRecord::Base  
  belongs_to :first, :class_name => "Message", :foreign_key => 'first_id'
  accepts_nested_attributes_for :first
  ...
end



<% form_for @channel do |f| %>

      <% f.fields_for :first do |g| %>
        <%= g.text_area :message %>
      <% end %>
   <%= f.submit  %>
<% end %>
A: 

Looks like you haven't populated @channel.first at the time the fields_for statement is rendered.

Ensure that there is an associated record by adding the following line to your controller or embed it in the template before the fields_for line:

@channel.build_first unless @channel.first
EmFi