From 3aeec3209c04219c3e78cce060e6c0e284e60108 Mon Sep 17 00:00:00 2001 From: Joseph Pecoraro Date: Fri, 29 May 2009 20:48:46 -0400 Subject: Clarification in an example. Grammar correction. --- railties/guides/source/form_helpers.textile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'railties/guides/source/form_helpers.textile') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index c4054a3205..0958c2c76a 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -211,9 +211,7 @@ h4. Binding a Form to an Object While this is an increase in comfort it is far from perfect. If Person has many attributes to edit then we would be repeating the name of the edited object many times. What we want to do is somehow bind a form to a model object, which is exactly what +form_for+ does. -Assume we have a controller for dealing with articles: - -articles_controller.rb: +Assume we have a controller for dealing with articles +app/controllers/articles_controller.rb+: def new @@ -221,9 +219,7 @@ def new end -The corresponding view using +form_for+ looks like this - -articles/new.html.erb: +The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks like this: <% form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %> @@ -584,7 +580,7 @@ h4. Dealing with Ajax Unlike other forms making an asynchronous file upload form is not as simple as replacing +form_for+ with +remote_form_for+. With an Ajax form the serialization is done by JavaScript running inside the browser and since JavaScript cannot read files from your hard drive the file cannot be uploaded. The most common workaround is to use an invisible iframe that serves as the target for the form submission. -h3. Customising Form Builders +h3. Customizing Form Builders As mentioned previously the object yielded by +form_for+ and +fields_for+ is an instance of FormBuilder (or a subclass thereof). Form builders encapsulate the notion of displaying form elements for a single object. While you can of course write helpers for your forms in the usual way you can also subclass FormBuilder and add the helpers there. For example -- cgit v1.2.3