Skip to content
Browse files

added documentation for :collection option, resolves #181

  • Loading branch information...
1 parent fd23ef4 commit a92cf7cb4fcd3a6a9294a65ca24e5d81cde3d70d @justinfrench committed Mar 13, 2010
Showing with 17 additions and 0 deletions.
  1. +17 −0 README.textile
View
17 README.textile
@@ -239,6 +239,23 @@ Customize the HTML attributes for the @<li>@ wrapper around every input with the
<% end %>
</pre>
+Many inputs provide a collection of options to choose from (like @:select@, @:radio@, @:check_boxes@, @:boolean@). In many cases, Formtastic can find choices through the model associations, but if you want to use your own set of choices, the @:collection@ option is what you want. You can pass in an Array of objects, an array of Strings, a Hash... Throw almost anything at it! Examples:
+
+<pre>
+ f.input :authors, :as => :check_boxes, :collection => User.find(:all, :order => "last_name ASC")
+ f.input :authors, :as => :check_boxes, :collection => current_user.company.users.active
+ f.input :authors, :as => :check_boxes, :collection => [@justin, @kate]
+ f.input :authors, :as => :check_boxes, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
+ f.input :author, :as => :select, :collection => Author.find(:all)
+ f.input :author, :as => :select, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
+ f.input :author, :as => :select, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
+ f.input :author, :as => :radio, :collection => User.find(:all)
+ f.input :author, :as => :radio, :collection => [@justin, @kate]
+ f.input :author, :as => :radio, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
+ f.input :author, :as => :radio, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
+ f.input :admin, :as => :radio, :collection => ["Yes!", "No"]
+</pre>
+
h2. The Available Inputs

0 comments on commit a92cf7c

Please sign in to comment.
Something went wrong with that request. Please try again.