Form Helpers

239 views
217 views

Published on

Form Helpers

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
239
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Form Helpers

  1. 1. PART ONE help! it's a Ruby on Rails FORM HELPERS cheat sheet guide by Amy Hoy Form helpers make building Rails-friendly forms super easy. Use 'em in views, including layouts and partials. Save time, save money! Form helpers belong to one of three groups: Step 1 * Form Tag Helpers create fields not based on your model except * create fields based on your model/objects Form Helpers date_helper! Form Options Helpers create select fields (lists, etc.) * the controller method to parse the form Start, submit, and end forms Step 2 <%= start_form_tag :action => 'update', :id => @books %> For forms that work from an existing object, use :id to specify the object. When creating new objects, the object name leave it off. the button's value (e.g. appearance) <%= submit_tag quot;Createquot; %> <%= end_form_tag %> no args here Understand the API docs Step 3a http://rails.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html There are just too many form helper methods for me to list 'em all. But for the form tags based on objects/models, there's a formula to make grokking the API docs a little easier. the singular name of the object/controller. options as hash parameters. e.g. quot;bookquot; or quot;userquot; or quot;articlequot; e.g. quot;rowsquot; => 50, or quot;sizequot; => 10 text_area(object, method, options = {}) the column name (really an ActiveRecord method) Real-world examples of #3 Step 3b <%= text_field quot;userquot;,quot;first_namequot;, quot;sizequot; => 25 %> <%= password_field quot;userquot;,quot;passwordquot; %> <%= text_area quot;bookquot;,quot;descriptionquot;, quot;rowsquot; => 20, quot;colsquot; => 90 %> © 2005 Amy Hoy / amy@infocookie.com / www.slash7.com License — see http://creativecommons.org/licenses/by-nc-sa/2.0/

×