Displaying 20 results from an estimated 30000 matches similar to: "Creating multiple child objects in a form"
2006 Jul 11
0
Arbitrary elements in form_for?
I would like to use form_for in my project so that I can easily change
the style of many forms at once. However, it seems to me like
FormBuilders only support certain kinds of form elements(!). Surely
there must be a way to add arbitrary labels/form elements to a form.
Let''s say I had a form that looks like:
ID: (plain-text label)
Name: (text field)
Birthdate: (date chooser)
Picture:
2007 Aug 20
0
FormBuilder in rjs
I have a page, which renders a partial that contains a ''State'' drop
down list. Upon change, it re-renders the ''City'' drop down, re-
populating it based on selected state_id:
Page: /customer/new.rhtml
<% form_for :customer, :url => customers_path do |f| %>
State: <%= f.collection_select :state_id, State.find(:all), ''id'',
2008 Dec 02
1
form_for with partial using do |@f|
Is it possible to pass this FormBuilder object to a controller and then
back to a partial?
I have a form rendering a partial that i would like to update with a
call to my controller based on user selectable parameters, but when the
AJAX comes back, i get this error message because i cannot pass a form
builder object between the controller and the view:
"undefined method
2006 Apr 23
3
custom form builder
In the API docs I found this:
"You can also build forms using a customized FormBuilder class. Subclass
FormBuilder and override or define some more helpers, then use your
custom builder "
I couldn''t find any further documentation on this. Where can I read more
about this formbuilder class? For starters, where would I define a
subclass of this class?
TIA,
Jeroen
--
2008 Dec 07
0
boolean button helper
I don''t have a blog, but wanted to share this little bit of code with
other semi-beginners like myself who are still learning to take
advantage of rails features.
Selecting an attribute with a boolean switch is a common pattern in
forms. You can do it with a check box, but radio buttons are more
expressive in some situations and better convey to the user that they
are making a mandatory
2006 May 31
1
Creating Multiple Child objects on a single form
I''ve been trying to solve this for the last few hours and I have
something that is working now but I''m curious if there isn''t a better
''right'' way to do it since this seems a bit of a cludge to me, but I
haven''t find a better way to make it work.
The models are as follows:
Goals, which have multiple objectives.
Goals also have multiple
2006 Apr 06
0
FormBuilder-friendly labels?
I''m trying to find a good way to emit <label> tags inside a form_for()
block, without needing to repeat the name of the instance variable
constantly. Is there a better way to do this than the snippet below,
or do I need to do a little extension to the FormBuilder itself?
<% form_for :long_example_name, @long_example_name,
:url => { :action => :new } do
2007 Oct 20
14
Problems with form_for and partials
i''m having problem with a form_for situation where i''m trying to DRY
out the repeated parts of my forms and put them in common/form and
render the form elements via another partial in controller_name/_form.
Here''s the first form
# app/views/common/form
<% form_for ... do |f| -%>
<%= render :partial => "params[:controller]/form", :object => f
2011 Sep 13
3
Accessing Rails helper method with_output_buffer
Hi all,
I cannot figure out how to correctly use the with_output_buffer helper
method (located in ActionView::Helpers::CaptureHelper) inside a custom
FormBuilder.
Below follows a simplified example.
I''m trying to achieve the following behavior in an ERB as suggested in
the form_for helper docs in the Rails source:
==========
<%= form_for @object, :builder => MyFormBuilder do
2005 Dec 27
2
Rewriting FormBuilder
Hi,
I want to extend formbuilder to make it output a lable (I know about
labeled_form_helper made by technoweenie), my own formating, and a
couple of extra tags inside the form attribute. I was easily able to
extend form_remote_to. But when I continue to adjust the way elements
are handled I don''t know how to continue. I can''t find the method
text_field thats should is
2006 Jan 18
22
Creating multiple child objects from the same form
I''ve been digging into rails, but this one question has been a two day
stumper. I''ve got a question/answer model that I''m trying to work out.
Each question has multiple answers (they''re more like choices, it
doesn''t matter whether they''re right or wrong), and I''d like to have the
question creation form also have multiple fields in
2006 May 26
1
Form for Multiple Models
I have a signup form that needs to do these three things:
1) create a new "Group"
2) create a new "User"
3) Add that User to the Group
I have the scaffolding for the create new user form:
<% form_for :user do |form| %>
<p>
<label for="user_name">First Name:</label>
<%= form.text_field
2010 May 28
8
form helpers don't seem to work with RJS files...
I’ve been spending a great deal of time chasing this problem. Hopefully
someone sees something obvious I’m doing wrong. Basically anytime I try
to call fields_for from an RJS file or within a partial in the RJS file,
I get the following error. My goal is simply to load a partial into a
div. The fields in this partial require fields_for though. And that’s
where the problem lies.
2006 Jul 27
2
Creating multiple objects from form data
I''m in the process of creating a sign up form for an online application.
The form collects account info, company info, and then info for an
administrative user.
The method looks like this:
def create
@account = Account.create!(params[:account])
@company = @account.companies.create!(params[:company])
@user = @company.users.create!(params[:user])
end
However, this inevitably fails
2006 Dec 05
1
Using render inside a FormBuilder (EdgeRails)
I''m using the latest trunk of 1.2-ish, and I''m wondering how to do what
I want to do. I am using a form_for :builder I wrote, simply called
TableFormBuilder after the rails cookbook, and want to be able to
present help icons automatically. I want these icons to appear next to
form fields I am rendering.
For example, I have this method in helpers/table_form_builder.rb:
# This
2011 Aug 02
2
removing instance variables in partials?
Hi,
I read some articles about why partials should not have instance
variables in them. But in "Ruby on Rails 3 Tutorial" the author starts
with this partial:
View:
<%= form_for(@user) do |f| %>
<%= render ''shared/error_messages'' %>
Partial:
<% if @users.errors.any? %>
...
...
I thought removing the @user instance variable from the partial
2009 Feb 05
1
[rspec] [rails] Specing a form builder
I''m trying to set up and run a new form builder under rails, which lives
under the helpers directory, but isn''t really a helper. (Not a module, so
doesn''t mix in well)
Short of dropping down into a view spec, how do I set up to actually spec
the form builder?
describe RandomFormBuilder do
attr_reader :builder
before do
@object = mock_model(Foo)
@builder =
2007 Sep 25
21
form_for and partials
I love form_for, but I really hate
<% form_for :person, @person, :url => {...} do |f| %>
...
<%= render :partial => ''form'', :locals => {''f'' => f}
...
<% end %>
I''ve been thinking of instead allowing
<% form_for :person, @person, :url => {...} do |f| %>
...
<%= f.partial ''form''
2009 Feb 06
2
Using partials with form_for
hi all
i was wondering whether it is possible to use partials along with form_for
and form_field. following code is not working. is there some error or this
case is impossible..??
*#new.html.erb*
<h1>Enter Details for new Partner:</h1>
<% form_for(@partner) do |f| %>
<%= render :partial => ''form'', :locals => {:partner => f} %>
<p>
2006 May 31
7
How do you create a controller & view to create a list of objects?
I''m trying to figure out how to design a view and controller to work with a
simple collection. I have a Foo that has many Bars, so here''s what I did:
$ ruby script/generate model Foo
$ ruby script/generate model Bar
(Uncomment t.column, :name: :string in foo and bar migrations)
(Edit Foo.rb and Bar.rb, add has_many :bars to Foo, belongs_to :foo to Bar)
$ rake db:migrate
$ ruby