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

  • Home
  • SEARCH
  • 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 920937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:47:49+00:00 2026-05-15T18:47:49+00:00

UPDATE: SOLUTION AT BOTTOM I’m hoping someone else has spent some time ironing out

  • 0

UPDATE: SOLUTION AT BOTTOM

I’m hoping someone else has spent some time ironing out this same issue… I’m building an address book within an rails application, and I have an Person model and an Email model. Person has_many Emails, and Person accepts_nested_attributes_for :emails.

This all works perfectly — I have a nested form with which I can add and remove emails and their attributes in my form (using a method similar to Railscasts 196-7 (here)). Submitting the form creates the Person, as well as the Emails, with all the correct associations.

The problem is, as it stands, I’m unable to find a way to use a select tag on the nested email model for the user to select a KIND (e.g. work, home, other) for that email. So, editing the Person model as I have it now, there is no easy way to select the attribute that is stored in the rails model.

Here’s what I have now:

<%= form_for(@source) do |f| %> 
<% f.fields_for :emails do |builder| %>  
. . . 
<%= builder.text_field :address, :size => 15 %>



<%= render :partial => 'email_select_1' %>0<%= render :partial => 'email_select_2' %>0<%= render :partial => 'email_select_3' %>

Note: the above is a hacky way of allowing me to set the ID later in javascript using the same code fragments. The partials spit out a hard-coded select and options, in this case ‘0’ but in javascript I can change it to a unique:

<select id="person_emails_attributes_0_kind" name="person[emails_attributes][0][kind]"><option value="work">work</option><option value="home">home</option><option value="other">other</option></select>

and then the rest looks like this (abbrev):

. . .
<% end %>  
. . .
<!-- more form stuff, actions, etc... -->
. . . 
<% end %>

Is there a way to use the select_tag helper for this, and replace my hacky-hard-coded select? If not, any suggestions for writing my own helper method?

Thanks in advance!

UPDATE: Thanks to Geoff for the solution. For posterity, the big thing is to use select, not select_tag. Then you can just do something like this:

<%= builder.select :kind, [['work', 'work'], ['home', 'home'], ['other', 'other']]%>
  • 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-05-15T18:47:50+00:00Added an answer on May 15, 2026 at 6:47 pm

    you should just need to pass the formbuilder variable to the partial. you would do so by coding your partial like this:

    <%= form_for(@source) do |f| %> 
      <% f.fields_for :emails do |builder| %>  
      . . . 
      <%= builder.text_field :address, :size => 15 %>
        <%= render :partial => 'email_select_1', :locals => {:builder => builder} %>
      <% end %>
    <% end %>
    

    And then your partial you would use:

    <%= builder.select :kind %>
    

    just as if it was within the fields_for block.

    Hope this helps!

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

Sidebar

Related Questions

Update: This issue is caused by bad memory usage, see solution at the bottom.
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: We are still using XP at work and I got my solution working,
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
See the solution at the bottom of the question. IE 8 (and lower) does
Update: Solved. See fix at bottom. In my iPad app which supports all orientations,
I know a variation on this has been asked several times; I've been browsing
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
Update: giving a much more thorough example. The first two solutions offered were right
Update: Solved, with code I got it working, see my answer below for the

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.