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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:42:16+00:00 2026-05-14T21:42:16+00:00

I am using rails3 beta3 and couchdb via couchrest. I am not using active

  • 0

I am using rails3 beta3 and couchdb via couchrest. I am not using active record.

I want to add multiple “Sections” to a “Guide” and add and remove sections dynamically via a little javascript. I have looked at all the screencasts by Ryan Bates and they have helped immensely. The only difference is that I want to save all the sections as an array of sections instead of individual sections. Basically like this:

"sections" => [{"title" => "Foo1", "content" => "Bar1"}, {"title" => "Foo2", "content" => "Bar2"}]

So, basically I need the params hash to look like that when the form is submitted. When I create my form I am doing the following:

<%= form_for @guide, :url => { :action => "create" } do |f| %>
  <%= render :partial => 'section', :collection => @guide.sections %>   
  <%= f.submit "Save" %>
<% end %>

And my section partial looks like this:

<%= fields_for "sections[]", section do |guide_section_form| %>
  <%= guide_section_form.text_field :section_title %>
  <%= guide_section_form.text_area :content, :rows => 3 %>
<% end %>

Ok, so when I create the guide with sections, it is working perfectly as I would like. The params hash is giving me a sections array just like I would want. The problem comes when I want edit guide/sections and save them again because rails is inserting the id of the guide in the id and name of each form field, which is screwing up the params hash on form submission.

Just to be clear, here is the raw form output for a new resource:

<input type="text" size="30" name="sections[][section_title]" id="sections__section_title">
<textarea rows="3" name="sections[][content]" id="sections__content" cols="40"></textarea>

And here is what it looks like when editing an existing resource:

<input type="text" value="Foo1" size="30" name="sections[cd2f2759895b5ae6cb7946def0b321f1][section_title]" id="sections_cd2f2759895b5ae6cb7946def0b321f1_section_title">
<textarea rows="3" name="sections[cd2f2759895b5ae6cb7946def0b321f1][content]" id="sections_cd2f2759895b5ae6cb7946def0b321f1_content" cols="40">Bar1</textarea>

How do I force rails to always use the new resource behavior and not automatically add the id to the name and value. Do I have to create a custom form builder? Is there some other trick I can do to prevent rails from putting the id of the guide in there? I have tried a bunch of stuff and nothing is working.

Thanks in advance!

  • 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-14T21:42:16+00:00Added an answer on May 14, 2026 at 9:42 pm

    Ok, I think I have figured out something that works. Changing the first line of the partial to:

    <%= fields_for "sections", section, :index => "" do |guide_section_form| %>
    

    Seems to work just fine. This way both new and edit form looks the same under the hood and the params hash works just like I need it to. If anyone sees anything wrong with this or has another alternative, please let me know.

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

Sidebar

Related Questions

Can any one help me to write this using rails3 active record query?? SQL-
I'm using rails 2.3.5 with i18n. I's there a way to find all not
I'm using the Rails3 beta, will_paginate gem, and the geokit gem & plugin. As
I'm using Rails3 (Windows, Ruby 1.8.7) with rufus-scheduler gem. Gem works fine, but if
I am using geokit-rails3 gem to find products in all colleges within range of
I'm using the rails3-jquery-autocomplete gem to autocomplete the name of a user, search attribute
I'm trying to deploy a Rails3 application, for the 1st time, to Dreamhost using
I'm Using Rails3 and the Unobstrusive Javascript Gem jquery-rails . Remote deletion (without page
I am using rails3 and I have a user model. This model has a
I am implementing a recipe search on rails3 using mysql. The idea of search

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.