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 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

Using Rails3 and Ruby 1.9.2, I am new, just learning Ruby/Rails-- When I run
I using rails3 and trying to build some complex associations. I have Product, Version
I'm using rails3 and I have the following bit in my routing.rb: resources :questions
I'm using rails3 with acl9 for authorization. I'm trying to grok ARel and the
I am using Rails 3 beta 4. I have the following models: class Player
Even though I know that, at least to my knowledge, this is not the
I would like to test a controller that directly renders some JSON output (by
When I invoke rake ts:rebuild RAILS_ENV=production , I get the following: (in /var/www/abc.com/public/abc/releases/20101008073517) **
My Gem file looks like this: source 'http://rubygems.org' gem 'rails', '3.0.0' # Bundle edge
I have two models and controllers: Snippets, and Tags. There is a belongs_to relationship,

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.