Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:12:35+00:00 2026-06-07T02:12:35+00:00

This is really simple, but i’m going slightly mad and probably missing something that’s

  • 0

This is really simple, but i’m going slightly mad and probably missing something that’s staring me in the face. Can anyone help?

Basically, I have a simple each loop that’s returning an extra rogue line. Even when there’s nothing in the db, I get one line returned!

My show view including the loop is:

  <p id="notice"><%= notice %></p>

<p>
  <b>Header:</b>
  <%= @mailer.header %>
</p>

<p>
  <b>Subtext:</b>
  <%= @mailer.subtext %>
</p>

<div id="" class="" padding-left: 30px;>    
<h3>Mailer Products </h3>

<ol id="mailer-Product-list">
<% @mailer.mailer_products.sort_by { |mailer_products| mailer_products.position }.each  do |mailer_product| %>
    <%= content_tag_for :li, mailer_product do %>
    <%= mailer_product.product.cat_no %>
<% end %>
<% end %>
</ol>   

    <%#= link_to 'Done', @product, :class => "standard-button" %>
</div>



<%= form_for([@mailer,@mailer.mailer_products.build]) do |f| %>

    <div class="field">
    <%= f.label :product_id %><br />
    <%= f.text_field :product_id %>
    </div>

    <div class="field">
    <%= f.hidden_field :mailer_id, :value => @mailer.id %>
    </div>

    <div class="actions">
    <%= f.submit "Add Product" %>
    </div>
<% end %>


<%= link_to 'Edit', edit_mailer_path(@mailer) %> |
<%= link_to 'Back', mailers_path %>

The controller code is:

class MailersController < ApplicationController

  def show
    @mailer = Mailer.find(params[:id])
     respond_to do |format|
      format.html # show.html.erb
      format.json { render :json => @mailer }
     end
   end

class MailerProductsController < ApplicationController

  def index
    @mailer_products = MailerProduct.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @mailer_products }
    end
  end
end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:12:37+00:00Added an answer on June 7, 2026 at 2:12 am

    Your call to form_for looks like this

    form_for([@mailer,@mailer.mailer_products.build]) do |f|
    

    You get an extra blank item because that’s what calling .build on mailer_products does: it appends a new instance to the array

    When the form is after the loop this doesn’t matter, but when things are the other way around the loop will be on the modified array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably something really simple but for some reason I just can't seem
This is probably something really simple but I cant see what! Any images I
This is frustrating me. It should be something really simple but I can't get
So this is probably really simple but for some reason I can't figure it
This seems really simple but I can't see that NSNumberFormatter has a function for
Hope you can help me with this its probably really simple but I'm pretty
I know this probably really simple but Im not sure what im doing wrong...
This is probably a really simple question but one I've never quite worked out
I'm sure this is really simple, but I can't for the life of me
I'm sure this is really simple, but I can't seem to get it working.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.