0

Currently, my nested form (the one for address) isn't showing up. It just shows the h1, and the submit button...

Relevant code:

class Address < ActiveRecord::Base
  belongs_to :user
  belongs_to :poll_option
  apply_addresslogic :fields => [[:number, :street], :city, [:state, :zip_code]]
end

class PollOption < ActiveRecord::Base
  belongs_to :poll
  has_one :address

  accepts_nested_attributes_for :address, :allow_destroy => true

end

<h1>Add a new address for voting</h1>

<% form_for @poll_option do |po_form| %>
  <%= po_form.error_messages %>

  <%= po_form.hidden_field :poll_id, :value => @poll.id %>

  <% po_form.fields_for :address do |addr_form| %>
      <%= addr_form.label :number %><br />
      <%= addr_form.text_field :number %><br />
      <br />
      <%= addr_form.label :street %><br />
      <%= addr_form.text_field :street %><br />
      <br />
      <%= addr_form.label :city %><br />
      <%= addr_form.text_field :city %><br />
      <br />
      <%= addr_form.label :state %><br />
      <%= addr_form.text_field :state %><br />
      <br />
      <%= addr_form.label :zip_code %><br />
      <%= addr_form.text_field :zip_code %><br />
      <br />
      <br />

  <% end %>

  <%= submit_tag "Create address and vote for this one" %>
<% end %>

1 Answer 1

1

If you're using Rails 3, you should be using <%= form_for .. and <%= f.fields_for ..., as the = on the tag indicates that it will output.

Additionally, in your controller's action that renders this form you need to be building the object (@poll_option.build_address or similar) so that the fields_for has an object to render.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.