-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
47 lines (32 loc) · 1.21 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
to_select
========
This plugin extends Array and ActiveRecord::Base adding a method to_select() to
create options for select helpers.
In the case of ActiveRecord::Base it will do a find(:all) and return a list with
all those records using the :name field to show the option and the :id to identify
the record.
In the case of Array it will expect it to be an array of ActiveRecord objects and
do the same thing, create a list using name an id fields.
On both cases the name field can be overriden using a parameter.
Example
=======
<% form_for @account do |form| %>
<%= f.select :branch_id, Branch.to_select %>
<% end %>
or
<% form_for @account do |form| %>
<%= f.select :branch_id, @branches.to_select %>
<% end %>
You can override the field name using a parameter:
<%= f.select :person_id, @people.to_select(:last_name) %>
Aditional Parameters
====================
* Conditions
<% form_for @account do |form| %>
<%= f.select :branch_id, Branch.to_select(:name, :conditions => {:active => true}) %>
<% end %>
* Default values
<% form_for @account do |form| %>
<%= f.select :branch_id, Branch.to_select(:name, :default => 'None') %>
<% end %>
Copyright (c) 2008 Carlos Kozuszko, released under the MIT license