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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:10:37+00:00 2026-05-18T07:10:37+00:00

This is hopefully a slam dunk for a Rails maven : I have a

  • 0

This is hopefully a slam dunk for a Rails maven :

I have a form that is supposed to iterate over a set of LineItems and gather information on each. I am trying to get form_for and fields_for to create the proper field names and parameters to give my controller a params hash something like

params[:line_items] = { <line_item.id> => { :rma_reason => "some string", :rma_qty => 2 } }

What I have is:

<% form_for(@object) do |rma_form| %>
  <% @order.line_items.each do |item| %>
  ....
    <% fields_for item do |item_f| %>
      <%= item_f.text_area :rma_reason %>
      <%= item_f.text_field :rma_qty, :value => item.quantity, :size=>3 %>
    <% end %>
  ....
  <% end %>
<% end %>

And the resultant HTML looks like (what you would expect, I guess):

<textarea id="line_item_id" name="line_item[id]"></textarea> 
<input id="line_item_rma_qty" name="line_item[rma_qty]" size="3" type="text" value="1" />

However what I am trying to get (and failing to find any solution beyond going back to ad-hoc HTML tags) is, field names that are indexed by the line_item.id, e.g. line_item[1928][rma_qty] for instance. This would allow my controller to iterate over each line_item and update it with the given params.

  • … maybe in a pure REST UI, the form should be tied to ONE instance of LineItem, and the standard form_for would work – but the user should be able to submit all the changes at once with one form. Is it possible?
  • 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-18T07:10:38+00:00Added an answer on May 18, 2026 at 7:10 am

    the fields_for needs to be called on the main form helper, and a string parameter with magic []s and an argument indicating which instance should be inserted in the []s

    <% rma_form.fields_for "line_item[]", item do |item_f| %>
    

    so now my tag looks something like

    <input id="return_authorization_line_item_1070870205_rma_qty" name="return_authorization[line_item][1070870205][rma_qty]" size="3" type="text" value="1" />
    

    which is peachy.

    this classic railscast is a good fields_for intro, and this comment explains the effect of the magic bracket that did what I wanted – other than that, couldn’t find this feature documented anywhere.

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

Sidebar

Related Questions

Hopefully this makes sense. I have a php script, magpierss, that parses a RSS
Rails newbie, thanks for help with this hopefully basic JSON type question.... I have
This is hopefully a simple question: I have an OpenGL texture and would like
Hopefully this is simple: I have a relatively long list where each list item
Hopefully this question isn't as subjective as I think it may be. I have
Hopefully this is less complex than I think. I have one table of companies,
This is hopefully my last question, for today :P. I have 10 .photo divs
Hopefully this question has a simple answer i'm overlooking! I have an IIS webserver
Hopefully this will be an easy question! I have two tables, a 'client(s)' table
This should hopefully be a quick one. I have a StringBuilder like so: StringBuilder

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.