In Ruby on Rails this creates a scope around a specific model object like #form_for, but doesn’t create the form tags themselves. This makes #fields_for suitable for specifying additional model objects in the same form.
Questions tagged [fields-for]
259 questions
105
votes
9 answers
Rails: fields_for with index?
Is there a method (or way to pull off similar functionality) to do a fields_for_with_index?
Example:
<% f.fields_for_with_index :questions do |builder, index| %>
<%= render 'some_form', :f => builder, :i => index %>
<% end %>
That partial…
![](../../users/profiles/147586.webp)
Shpigford
- 22,682
- 52
- 149
- 235
32
votes
2 answers
Rails 3 fields_for - sort order gets lost
I am using Rails 3.0.3 with ruby 1.9.2p0.
In my profiles_controller (edit function) I have this call
@profile = Profile.find(params[:id])
@profile_items = @profile.profile_items.order("pos")
to get the @profile_items in the correct order, sorted…
![](../../users/profiles/611990.webp)
Michael Lindström
- 321
- 3
- 3
26
votes
2 answers
fields_for not rendering - rails 3
Finally moved to Rails 3 for a new project and already running into a rookie problem.
Trying to do a simple nested form.
2 models: list and tasks
List model
class List < ActiveRecord::Base
has_many :tasks, :dependent=>:destroy
…
![](../../users/profiles/387952.webp)
Ryan
- 379
- 1
- 5
- 11
19
votes
4 answers
using an array with fields_for
How can I iterate through an array of objects (all the same model) using fields_for ?
The array contains objects created by the current_user.
I currently have:
<%= f.fields_for :descriptionsbyuser do |description_form| %>
<%=…
![](../../users/profiles/668846.webp)
adamteale
- 822
- 2
- 11
- 25
18
votes
2 answers
How should I use rails and simple_form for nested resources?
I'm trying to create one resource with another nested resource at the same time. I'm using Rails4 and simple_form 3.0.0rc. Here is my code.
Models:
class User < ActiveRecord::Base
has_one :profile
accepts_nested_attributes_for…
![](../../users/profiles/2716623.webp)
vasily.sib
- 3,571
- 2
- 19
- 25
16
votes
1 answer
Rails 4: fields_for in fields_for
I am learning RoR and i am trying to find how to set a fields_for in another one with has_one models like this:
class Child < ActiveRecord::Base
belongs_to :father
accepts_nested_attributes_for :father
end
class Father < ActiveRecord::Base
…
![](../../users/profiles/3029400.webp)
user3029400
- 387
- 1
- 5
- 13
13
votes
4 answers
Forms to create and update Mongoid array fields
I've been struggling to create a form for a Mongoid model that has an array field. I want my form to have on text box per entry in the array. If I'm creating a new record, the default will be one empty field (and some javascript to add new fields…
![](../../users/profiles/35341.webp)
Dave Jensen
- 4,444
- 1
- 38
- 43
11
votes
1 answer
Fields_for disappear when adding accepts_nested_attributes_for
I'm doing a nested form in Rails 3.2.5, but when I add the accepts_nested_attributes_for my fields_for disappear (they just stop showing in my form).
This are my models:
class Product < ActiveRecord::Base
attr_accessible :title,…
![](../../users/profiles/593998.webp)
Acuña
- 295
- 2
- 8
10
votes
3 answers
How do I change the html tag and class generated by fields_for?
This is a simple question that I'm kinda ashamed to ask, but I've been banging my head against the wall and navigating through the rails 3 documentation without any success :/
So, here is the thing:
When I use the fields_for helper it wraps the…
![](../../users/profiles/285954.webp)
Hector Villarreal
- 802
- 9
- 19
9
votes
1 answer
Indexing on nested form with multiple `fields_for`
Given the model Album has_many Song and the latter with localized fields such as:
Song#name_en
Song#description_en
Song#name_fr
Song#description_fr
[...]
Due to the frontend design, I can't do one f.simple_fields_for :songs in one place for all the…
![](../../users/profiles/658651.webp)
svoop
- 2,956
- 19
- 34
9
votes
1 answer
using fields_for in several places
I have a simple model
class Ad < ActiveRecord::Base
has_many :ad_items
end
class AdItem < ActiveRecord::Base
belongs_to :ad
end
I have an "ads/new" view, that shows me the form for creating the new ad and adding some items to it
The…
![](../../users/profiles/235158.webp)
AntonAL
- 14,493
- 19
- 71
- 109
8
votes
1 answer
rails 3 form_for doesn't output anything
Hi I have any form with nested form, for example
<% form_for :main do |f| %>
trying to insert code here
<% fields_for :nested do |nested_form| %>
<%= nested_form.text_field :description %>
<% end %>
<% end %>
And then I am trying to…
![](../../users/profiles/520216.webp)
henrik
- 133
- 1
- 7
8
votes
3 answers
Fields_for dynamic label
I have dynamic form which has a set of values. I created a partial which contains text fields which I display. Next to each of them I would like to display a label containing the title of the text. For instance First Name, and Last Name would not be…
![](../../users/profiles/287767.webp)
sebajb
- 161
- 4
7
votes
1 answer
Absolutely stuck trying to create nested association in rails form with has_many through
I posted an earlier question about this and was advised to read lots of relevant info. I have read it and tried implementing about 30 different solutions. None of which have worked for me.
Here's what I've got.
I have a Miniatures model.
I have a…
![](../../users/profiles/2711219.webp)
Ossie
- 1,003
- 2
- 12
- 28
6
votes
1 answer
Rails 3: nested_form, collection_select, accepts_nested_attributes_for and fields_for
Update: answered here.
There are lots of good questions and answers here and on the interweb about getting nested_form, collection_select, accepts_nested_attributes_for and fields_for to play nicely together, but I'm still stumped. Thanks in…
![](../../users/profiles/721631.webp)
snowangel
- 3,299
- 3
- 24
- 67