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 8882807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:40:07+00:00 2026-06-14T20:40:07+00:00

I have form partial that allows the user to enter the subject and message

  • 0

I have form partial that allows the user to enter the subject and message that will be included in the outbound email. I want to allow the users to select the recipients of the email from the contacts that are associated with the invoice that the email belongs to. The email recipients that are selected through the nested form are to be stored in a separate table.

class EmailRecipient < ActiveRecord::Base
  attr_accessible :contact_id, :email_id

  belongs_to :email

end

class Email < ActiveRecord::Base
  attr_accessible :subject, :message, :invoice_id, :email_recipients_attributes

  belongs_to :invoice
  has_many :email_recipients

  accepts_nested_attributes_for :email_recipients

end

<%= simple_form_for [:invoice, @email], html: {class: "form-horizontal"} do |f| %>
  <%= f.error_notification %>

  <% @invoice.contacts do |c|%>
    <%= f.fields_for :email_recipients do |builder| %>
      <%= builder.input :contact_id, :as => :check_boxes %>
      <%= c.name %><br/>    
    <% end %>
  <% end %>

  <%= f.input :subject, :as => "string" %>
  <%= f.input :message, :input_html => { :class => 'span7', :rows => 10 } %>

  <div class="form-actions">
    <%= f.button :submit, "Send Invoice", :class => 'btn-warning' %>
    <%= link_to 'Cancel', invoice_path(@invoice), :class => 'btn' %>
  </div>
<% 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-14T20:40:08+00:00Added an answer on June 14, 2026 at 8:40 pm

    This isn’t the prettiest answer, so I would love to see a better solution, but it gets the job done until my skills improve.

    In the controller for the parent form I added:

    @invoice.contacts.each { |c| @email.email_recipients.build(contact_id: c.id) }
    

    This builds the records for all contacts whether they are needed or not. Then in the form partial I modified the nested form:

    <%= simple_form_for [:invoice, @email], html: {class: "form-horizontal"} do |f| %>
      <%= f.error_notification %>
      <% count = 0 %>
      <%= f.simple_fields_for :email_recipients do |email_recipients_form| %>
        <%= email_recipients_form.input :_destroy, as: :boolean, :label => false do %>
          <%= email_recipients_form.check_box :_destroy, {}, "false", "true" %>
          <% contact = @invoice.contacts.find(@email.email_recipients[count].contact_id) %>
          <%= contact.name + " (" + contact.email + ")" %>
        <% end %>
      <%= email_recipients_form.input :contact_id, as: :hidden %>
      <% count += 1 %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that allows a user to select what report they want
On a view, i have a partial view rendering an ajax form that allows
I have a generic 'form page' user control that we use that allows editors
if i have created a view model and have a partial form that is
I have this windows app Cafe that allows the user to make their selection
I have been asked to write a GUI that will allow objects to be
I have the below code that allows a user to write in a executable
Say I want to create a form that allows you to add elements dynamically
I'm having an issue with a form that I have. The form allows users
I have a form partial that looks like this: <%= form_for(@pool) do |f| %>

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.