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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:27:28+00:00 2026-05-20T10:27:28+00:00

I’m actually just copying an old question from railsforum as he asked it back

  • 0

I’m actually just copying an old question from railsforum as he asked it back in May ’09 and the only reply is the authors own inelegant fix. I wondered if anybody knows of a better way? Otherwise I’m going to end up using javascript to move the hidden field about as he has.

Here’s the original question:


Hi there!
Grateful for any good advice on this topic:

Is it possible to override Rails’ automatic generation of hidden ID fields in the fields_for for a has_many association? I would like to generate my own so that I can choose where the thing goes.

Here’s why:

I am trying to put a jQuery-ui Accordion widget around a form that looks a bit like this:

<div id="diagram_elements_form">
    <% diagram_form.fields_for :elements do |element_fields| %>
        <% link_to "#" do %>
            <%= element_fields.object.name %>
        <% end %>
        <%= render :partial => "edit_element_base", :locals => { :f => element_fields }  %>
    <% end %>
</div>

the model, simplified, looks like:

class Diagram < ActiveRecord::Base
    has_many :elements
    accepts_nested_attributes_for :elements
end

I think I’ve got the model/controller stuff right because I can CRUD to my heart’s content. But the accordion comes out all screwy.

the jQuery UI/Accordion widget looks for html in the form of:

<div id="accordion">
    <a href="#">First header</a>
    <div>First content</div>
    <a href="#">Second header</a>
    <div>Second content</div>
</div>

This seems like an easy thing to accomplish with rails, but I am really choking.
The tabs show up but are skewed, and finally I realized it’s because of the hidden_field that rails automatically adds for each object in the fields_for. What I wind up with looks like this:

<div id="accordion">
    <input type="hidden" name="...id" value="2" />
    <a href="#">First header</a>
    <div>First content</div>
    <input type="hidden" name="...id" value="3" />
    <a href="#">Second header</a>
    <div>Second content</div>
</div>

… Such that the hidden fields are getting taken as part of the accordion structure. I would like to move the ID fields inside of the DIV tags. Any ideas?

thanks again,
Tyler


I’m having exactly the same issue as Tyler here. The hidden fields generated by fields_for are messing up the accordion UI and at the moment I can’t see a way to change the position of them except moving them with javascript.

I shall post a link to this back on railsforum so that hopefully Tyler will receive any benefit of your collective wisdom as well.

Regards,

Kevin.

  • 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-20T10:27:29+00:00Added an answer on May 20, 2026 at 10:27 am

    Since Rails 2.3.5 you can place a f.hidden_field(:id) where you would like it to exist, and Rails will fill out the details.

    The ticket regarding this change is available here.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.