From 85637ddc2e341cdf05e668a011012f8618f290f5 Mon Sep 17 00:00:00 2001 From: Justin French Date: Wed, 5 Nov 2014 20:26:19 +1100 Subject: [PATCH] document Model.pluck usage in :collection option --- README.textile | 3 +++ lib/formtastic/inputs/check_boxes_input.rb | 1 + lib/formtastic/inputs/radio_input.rb | 2 ++ lib/formtastic/inputs/select_input.rb | 2 ++ 4 files changed, 8 insertions(+) diff --git a/README.textile b/README.textile index 37af466b2..6e749ae08 100644 --- a/README.textile +++ b/README.textile @@ -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 diff --git a/lib/formtastic/inputs/check_boxes_input.rb b/lib/formtastic/inputs/check_boxes_input.rb index d2d5efbbb..083d3f1da 100644 --- a/lib/formtastic/inputs/check_boxes_input.rb +++ b/lib/formtastic/inputs/check_boxes_input.rb @@ -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"]] %> diff --git a/lib/formtastic/inputs/radio_input.rb b/lib/formtastic/inputs/radio_input.rb index a5b05095c..3aa981677 100644 --- a/lib/formtastic/inputs/radio_input.rb +++ b/lib/formtastic/inputs/radio_input.rb @@ -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"]] %> diff --git a/lib/formtastic/inputs/select_input.rb b/lib/formtastic/inputs/select_input.rb index f3171ef3a..8fc65c195 100644 --- a/lib/formtastic/inputs/select_input.rb +++ b/lib/formtastic/inputs/select_input.rb @@ -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"]] %>