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]
264 questions
109
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…

Shpigford
- 24,748
- 58
- 163
- 252
34
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…

Michael Lindström
- 341
- 1
- 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
…

Ryan
- 379
- 1
- 5
- 11
21
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…

vasily.sib
- 3,871
- 2
- 23
- 26
21
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| %>
<%=…

adamteale
- 940
- 2
- 12
- 27
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
…

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…

Dave Jensen
- 4,574
- 1
- 40
- 45
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,…

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…

Hector Villarreal
- 822
- 10
- 20
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…

svoop
- 3,318
- 1
- 23
- 41
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…

AntonAL
- 16,692
- 21
- 80
- 114
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…

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…

sebajb
- 161
- 1
- 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…

Ossie
- 1,103
- 2
- 13
- 31
7
votes
2 answers
grouping and fields_for
I'm trying to create a form which allows me to submit new records for an association where the association inputs are grouped.
class Product < AR::Base
has_many :properties
accepts_nested_attributes_for :properties
end
Note that in…

Kris
- 19,188
- 9
- 91
- 111