Displaying 20 results from an estimated 7000 matches similar to: "Can I use an array with fields_for ?"
2006 Jul 05
0
Javascript repeating fields.
The one area I keep hitting my head against in Rails is repeating fields via
javascript. I frequently have forms where one or more fields are actually
broken out into sub tables because there can be multiple simultaneous values.
Rails seems to want to you to use the [] construct in the form helpers (e.g.
text_field(''employee[]'', ''name'')), but I can''t
2009 Oct 15
4
Getting the object in fields_for
I''m using the fields_for helper with accepts_nested_attributes_for
The System model has_many children.
If I do this in my haml template:
-form_for @system do |s|
=s.text_field :name
-s.fields_for :children do |child_fields|
=child_fields.text_field :name
all is fine. The fields_for iterates over all children and puts the
correct data in the fields.
But...what I
2009 Oct 15
1
fields_for weirdness
I just did a large upgrade to to Rails 2.3.4 and I am trying to make
use of the more modern view features.
I have a Newsletter object. Newsletter has many Sections.
I also have:
accepts_nested_attributes_for :sections
on the Newsletter object.
I have the typical scaffolded new.html.erb with:
<% form_for(@newsletter) do |f| %>
in there, I am trying to populate the first Section
2006 May 16
1
fields_for giving undefined method exception
I''m getting an undefined method exception with the fields_for method.
I''m following the gem examples. The form_for works but when I add
fields_for it breaks.
Are there other examples of how this works anywhere?
--
Posted via http://www.ruby-forum.com/.
2012 Aug 25
0
accepts_nested_attributes_for and fields_for not working!
I want to be able to create one menu object that has fields_for :brunch,
:lunch, and :dinner. The menu object has_many brunches, lunches, and
dinners, but each time I "edit", only one brunch, one lunch, and one dinner
object are added. I''m using carrierwave to upload brunch_menus,
lunch_menus, and dinner_menus (attributes of brunches, lunches, and dinners
respectively) as
2012 Jan 20
3
Fields_for adding html (text) for hidden field
Hello all,
I''m getting this weird ''<input name value=''2'' type=''hidden'' />'' text
printed out in my form. See attached image. I''ve spent too much time
trying to figure it out already and it''s not going to stop me from
moving on for now.
As you can see it''s still very early on.
I''m using
2008 May 02
1
names of select elements inside a fields_for block not generated as expected
Hey All,
I''m trying to play along w/the ''complex forms 1'' railscast
(http://railscasts.com/episodes/73) and having trouble. The view is
projects/new. I''m trying to add some project_people to the form w/code
like so:
<% form_for(@project) do |f| %>
[project stuff here]
<% for pp in @project.project_person %>
<% fields_for
2009 Feb 09
2
how to get form parameters while using fields_for with nested attributes
hi all..
i am trying to use *fields_for* to get and save nested attributes in a form.
i have a ''Partner'' model associated with an ''Address'' model.
partner has_many :addresses
although the form is displaying fine, but on submitting it the following
error is shown:
*can''t convert HashWithIndifferentAccess into Array*
on this line:
*@partner =
2011 Jul 25
4
[Rails 3.0.9] I have trouble about fields_for
Hi,all. I''m new bee to Rails and I have trouble about fields_for
method..
It isn''t show up between the <%= f.fields ~ <% end %>
Please teach me some advice.
Thanks!
#new/_form.html.erb
<%= form_for(@user) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<!-- Below
2007 Nov 14
0
Problem time_select with fields_for
Hi,
I''m using fields_for and a time_select but he isn''t saving the time in
the db just 00:00:00
All the other fields are fine, but the time_field isn''t working:s
This is my code:
<% form_for :activity, @activity,:url => {:action => "create"} do
|activity_form| %>
<td><%= activity_form.time_select :datum_1_twrak_van, :order =>[ :hour,
2007 Feb 16
0
Please help...passing arrays between controller and view
I have tried to get this question answered before with no success. I''m
getting desperate!
Here is a simplified description of my problem...
I have a many-to-many relationship between accounts and employees, with
a model table in between called AccountEmployeeRelations. There is
other stuff in this table, but I don''t think that matters for now.
In the controller I create
2013 Dec 10
2
form_tag + fields_for Rails 4
Hi There,
I''m trying to user fields_for inside a form_tag, but i can''t catch it
on my controller.
I just take some html code off to makes it easy to read
my view...
i''m using campuses_path(current_church, @campus) instead form_for
@campus, because my route is like
resources :campuses, :path => ":church/campuses"
<%= form_tag
2011 Apr 22
0
how to set up fields_for to choose a subclass?
I have an STI model where UtilityProvider is the parent class, and
there''s a sub-class for each specific utility provider.
When the user goes to choose a UtilityProvider, I want to present a
pull-down list of UtilityProvider.subclasses (or, more likely, a
filtered version of that), and when the user hits [submit] to create the
appropriate subclass.
To add a little spice to the question,
2013 Mar 04
0
fields_for with accepts_nested_attributes: how to pass a value to a label
I can''t figure out how to pass a value from the following object build in
the controller:
class TimesheetsController < AC
...
def new
@timesheet = current_user.timesheets.new
now = Date.today
#generating 7 time entries: monday through sunday
(now.beginning_of_week..now.end_of_week).step { |date|
@timesheet.time_entries.build(:workdate; date)
end
end
...
In the
2008 Dec 21
1
Form issues : partials + AJAX vs simple JS / separate views + form_fors vs one view and fields_fors
Hi all!
I am coding an application that keeps track of request to create
college courses. An identified user (logically a faculty member)
completes a form indicating the name of the course, the professor in
charge, the course''s code, the date and place, the possible
coprofessors and TAs and the type of website he or she wants to use as
a teaching help (WebCT, Sakai, etc.).
I have two
2009 Feb 18
5
fields_for and Conflicting types for parameter containers. Expected an instance of Hash but found an instance of Array.
I''m trying to use ''fields_for'' in a form. I want the same form to
support both the creation of new obejcts as well as the editing of old
ones. So - in my controller, sometimes I will pass to the form an
object that already exists in my database and has an id and other
times I will pass it a newly created instance of an object that does
not yet exist in the database and
2008 Dec 02
4
Am I wrong or is fields_for not working right in Rails 2.2.2
I may be totally wrong about what the fields_for method is supposed to
do, but for some reason I thought using it scoped an object around an
association.
For example, I have a User class and when you''re creating a new user I
want to use fields_for to add a BillingAddress to the user like so:
<%- fields_for :billing_address do |billing_address_form| -%>
<%= render :partial
2009 Nov 27
0
Trying to use form_for or fields_for to get one record for display
The reason I''m doing this is that the app is for a foodbank, and I''m
trying to use a model as an attendance list. The model will have a
date field, with a new record for each month. I need to display only
the record for the current month, as way to safeguard against someone
visiting too often. I''d like to use checkboxes for when a person
attended this month, which is the
2009 May 12
2
2.3 Nested Model Forms; build new without updating existing
I''m trying to build something similar to a Facebook messaging app, in
which the view displays all the messages for a particular thread, with
a form box for replying at the bottom of the thread.
The problem is that using fields_for generates form fields for each
existing record, and for one new record. In this case, there is no
need to edit existing messages - just a need to add new
2006 Aug 14
1
What fields_for really for?
Hello everyone!
I have 3 models:
=== 1 ===
class Region < ActiveRecord::Base
has_many :districts
end
=== 2 ===
class District < ActiveRecord::Base
belongs_to :region
has_many :suburbs
end
=== 3 ===
class Suburb < ActiveRecord::Base
belongs_to :district
validates_numericality_of :region_id, :only_integer => true
end
In edit.rhtml for SuburbController I need to specify