Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing nested forms in Rails - How can I make the show page display every new entry in a table format depending on how many presents the user wants?
    primarykey
    data
    text
    <p>I have a baby present registry I'm building with Rails 3.2. There is a registry model and a present model nested under the registry model. Everything works 100% except in the show page.</p> <p>When a user creates a registry he/she can add presents through the add presents tag (as many as he/she wants), but the problem is in the show page it only the first present is displayed as I want it too. The rest is displayed in plain non formatted text.</p> <p>Any help please? I would like it to show in a table format. </p> <p>Here is my code: Here is the Registry Form:</p> <pre><code>&lt;%= nested_form_for(@registry) do |f| %&gt; &lt;% if @registry.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@registry.errors.count, "error") %&gt; prohibited this registry from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @registry.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;%= f.label :due_date %&gt;&lt;br /&gt; &lt;%= f.date_select :due_date, :rows =&gt; 5 %&gt; &lt;%= f.label :theme %&gt;&lt;br /&gt; &lt;%= f.text_field :theme, :class =&gt; 'field2' %&gt; &lt;div class="field1"&gt; &lt;%= f.label :gender %&gt;&lt;br /&gt; &lt;%= f.text_field :gender %&gt; &lt;/div&gt; &lt;div class="field1"&gt; &lt;%= f.fields_for :presents do |builder| %&gt; &lt;%= render 'present_fields', f: builder %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;%= link_to_add_fields "Add Presents", f, :presents %&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>The presents_fields:</p> <pre><code>&lt;div class="field1"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;%= f.label :type, "Present Type" %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.text_field :type, :class =&gt; 'field2' %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.label :Quantity, "Quantity" %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.number_field :quantity, :class =&gt; 'field3' %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.label :color, "Color" %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.text_field :color, :class =&gt; 'field2' %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.label :brand, "Brand" %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.text_field :brand, :class =&gt; 'field2' %&gt; &lt;/td&gt; &lt;td&gt; &lt;%= f.link_to_remove "Remove this present" %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>The show page: &lt;% provide(:title, 'My Party and Present Whishes') %> &lt;%= notice %></p></p> <pre><code>&lt;p&gt; Baby &amp; Party Details: &lt;/p&gt;&lt;/br&gt; &lt;li&gt;&lt;p&gt; Due date: &lt;/p&gt; &lt;%= @registry.due_date %&gt;&lt;/li&gt;&lt;/br&gt; &lt;li&gt;&lt;p&gt; Party Theme: &lt;/p&gt;&lt;%= @registry.theme %&gt;&lt;/li&gt;&lt;/br&gt; &lt;li&gt;&lt;p&gt; Gender: &lt;/p&gt;&lt;%= @registry.gender %&gt;&lt;/li&gt;&lt;/br&gt; &lt;p&gt; Presents Registry: &lt;/p&gt;&lt;/br&gt; &lt;li&gt; &lt;% @registry.presents.each do |registry| %&gt; &lt;%= registry.type %&gt; &lt;%= registry.quantity %&gt; &lt;%= registry.color %&gt; &lt;%= registry.brand %&gt; &lt;/li&gt; &lt;% end %&gt; &lt;/br&gt; &lt;/br&gt; &lt;%= link_to 'Edit', edit_registry_path(@registry) %&gt; &lt;%= link_to 'Back', registries_path %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload