dm-is-select
A DataMapper plugin that makes getting
the <select>
options from a Model easier.
Namespace
Methods
Constants
VERSION | = | IO.read("#{File.dirname(__FILE__)}/../../VERSION").chomp |
Instance Public methods
is_select(select_field = :name, options = {})
Link
Defines the field to use for the select menu
Params
-
:field_name => the name of the field values shown in select
-
:options
-
:is_tree => whether if the current Model is an is :tree model. (Defaults to false)
-
Examples
is :select, :name => creates a <select> options array on the :name attribute of the model is :select, :name, :is_tree => true => creates a <select> options array with the results ordered in hierarchical order parent > child > grandchild for each parent is :select, :name, :value_field => :code => creates a <select> options array with the results ordered in hierarchical order parent > child > grandchild for each parent
@api public
Source: show
# File lib/is/select.rb, line 39 def is_select(select_field = :name, options = {}) raise ArgumentError, "The :select_field, must be an existing attribute in the Model. Got [ #{select_field.inspect} ]" unless properties.any?{ |p| p.name == select_field.to_sym } @select_options = { :value_field => "id", # add specical features if we are working with Tree Model :is_tree => false }.merge(options) @select_field = select_field @value_field = @select_options[:value_field] # Add class & Instance methods extend DataMapper::Is::Select::ClassMethods # include DataMapper::Is::Select::InstanceMethods end