PART ONE

help! it's

FORM HELPERS

a Ruby on Rails
cheat sheet guide
by Amy Hoy

Form helpers make building Rails-friendl...
Upcoming SlideShare
Loading in …5
×

Ruby on rails cheat sheet form helpers

694 views

Published on

Auxiliar de Forms do Roby on Rails

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
694
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Ruby on rails cheat sheet form helpers

  1. 1. PART ONE help! it's FORM HELPERS a Ruby on Rails 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! Step 1 Step 2 Form helpers belong to one of three groups: * * * Form Tag Helpers create fields not based on your model create fields based on your model/objects Form Helpers Form Options Helpers create select fields (lists, etc.) Start, submit, and end forms the controller method to parse the form <%= 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, leave it off. the button's value <%= submit_tag "Create" %> <%= end_form_tag %> Step 3a except date_helper! the object name (e.g. appearance) no args here Understand the API docs 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. e.g. "book" or "user" or "article" options as hash parameters. e.g. "rows" => 50, or "size" => 10 text_area(object, method, options = {}) the column name (really an ActiveRecord method) Step 3b Real-world examples of #3 <%= text_field "user","first_name", "size" => 25 %> <%= password_field "user","password" %> <%= text_area "book","description", "rows" => 20, "cols" => 90 %> © 2005 Amy Hoy / amy@infocookie.com / www.slash7.com License — see http://creativecommons.org/licenses/by-nc-sa/2.0/

×