Skip to content

Commit

Permalink
document Model.pluck usage in :collection option
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Nov 5, 2014
1 parent 2c13644 commit 85637dd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.textile
Expand Up @@ -308,6 +308,9 @@ Many inputs provide a collection of options to choose from (like @:select@, @:ra
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.all
f.input :author, :as => :select, :collection => Author.pluck(:first_name, :id)
f.input :author, :as => :select, :collection => Author.pluck(Arel.sql("CONCAT(`first_name`, ' ', `last_name`)"), :id)
f.input :author, :as => :select, :collection => Author.your_custom_scope_or_class_method
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.all
Expand Down
1 change: 1 addition & 0 deletions lib/formtastic/inputs/check_boxes_input.rb
Expand Up @@ -39,6 +39,7 @@ module Inputs
# <%= f.input :categories, :as => :check_boxes, :collection => @categories %>
# <%= f.input :categories, :as => :check_boxes, :collection => Category.all %>
# <%= f.input :categories, :as => :check_boxes, :collection => Category.some_named_scope %>
# <%= f.input :categories, :as => :check_boxes, :collection => Category.pluck(:label, :id) %>
# <%= f.input :categories, :as => :check_boxes, :collection => [Category.find_by_name("Ruby"), Category.find_by_name("Rails")] %>
# <%= f.input :categories, :as => :check_boxes, :collection => ["Ruby", "Rails"] %>
# <%= f.input :categories, :as => :check_boxes, :collection => [["Ruby", "ruby"], ["Rails", "rails"]] %>
Expand Down
2 changes: 2 additions & 0 deletions lib/formtastic/inputs/radio_input.rb
Expand Up @@ -78,6 +78,8 @@ module Inputs
# <%= f.input :author, :as => :radio, :collection => @authors %>
# <%= f.input :author, :as => :radio, :collection => Author.all %>
# <%= f.input :author, :as => :radio, :collection => Author.some_named_scope %>
# <%= f.input :author, :as => :radio, :collection => Author.pluck(:full_name, :id) %>
# <%= f.input :author, :as => :radio, :collection => Author.pluck(Arel.sql("CONCAT(`first_name`, ' ', `last_name`)"), :id)) %>
# <%= f.input :author, :as => :radio, :collection => [Author.find_by_login("justin"), Category.find_by_name("kate")] %>
# <%= f.input :author, :as => :radio, :collection => ["Justin", "Kate"] %>
# <%= f.input :author, :as => :radio, :collection => [["Justin", "justin"], ["Kate", "kate"]] %>
Expand Down
2 changes: 2 additions & 0 deletions lib/formtastic/inputs/select_input.rb
Expand Up @@ -94,6 +94,8 @@ module Inputs
# <%= f.input :author, :as => :select, :collection => @authors %>
# <%= f.input :author, :as => :select, :collection => Author.all %>
# <%= f.input :author, :as => :select, :collection => Author.some_named_scope %>
# <%= f.input :author, :as => :select, :collection => Author.pluck(:full_name, :id) %>
# <%= f.input :author, :as => :select, :collection => Author.pluck(Arel.sql("CONCAT(`first_name`, ' ', `last_name`)"), :id)) %>
# <%= f.input :author, :as => :select, :collection => [Author.find_by_login("justin"), Category.find_by_name("kate")] %>
# <%= f.input :author, :as => :select, :collection => ["Justin", "Kate"] %>
# <%= f.input :author, :as => :select, :collection => [["Justin", "justin"], ["Kate", "kate"]] %>
Expand Down

0 comments on commit 85637dd

Please sign in to comment.