-
Notifications
You must be signed in to change notification settings - Fork 0
A simple rails plugin to make it easier to pass options to the select helper.
License
insignia/to_select
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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
About
A simple rails plugin to make it easier to pass options to the select helper.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published