Class: RailsAdmin::Config::Fields::Base
- Includes:
- Hideable
- Defined in:
- lib/rails_admin/config/fields/base.rb
Direct Known Subclasses
Association, Types::Boolean, Types::Color, Types::Datetime, Types::Decimal, Types::Enum, Types::FileUpload, Types::Float, Types::Hidden, Types::Integer, Types::String, Types::Text
Instance Attribute Summary collapse
-
#defined ⇒ Object
Returns the value of attribute defined.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
Returns the value of attribute order.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#section ⇒ Object
Returns the value of attribute section.
Attributes inherited from Base
#abstract_model, #bindings, #parent, #root
Class Method Summary collapse
Instance Method Summary collapse
- #_html_attributes ⇒ Object
-
#association? ⇒ Boolean
Is this an association.
- #editable ⇒ Object
-
#errors ⇒ Object
Reader for validation errors of the bound object.
-
#initialize(parent, name, properties) ⇒ Base
constructor
A new instance of Base.
- #inverse_of ⇒ Object
- #method_name ⇒ Object
-
#nested_form ⇒ Object
Reader for nested attributes.
-
#optional(state = nil, &block) ⇒ Object
Inverse accessor whether this field is required.
-
#optional=(state) ⇒ Object
Writer to make field optional.
-
#optional? ⇒ Boolean
Reader whether field is optional.
- #render ⇒ Object
-
#type ⇒ Object
Reader for field’s type.
- #type_css_class ⇒ Object
-
#value ⇒ Object
Reader for field’s value.
- #virtual? ⇒ Boolean
Methods included from Hideable
#hidden?, #hide, included, #show
Methods inherited from Base
#has_option?, register_class_option, #register_deprecated_instance_option, register_deprecated_instance_option, register_instance_option, #register_instance_option, #with
Constructor Details
#initialize(parent, name, properties) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_admin/config/fields/base.rb', line 22 def initialize(parent, name, properties) super(parent) @defined = false @name = name @order = 0 @properties = properties @section = parent extend RailsAdmin::Config::Fields::Groupable end |
Instance Attribute Details
#defined ⇒ Object
Returns the value of attribute defined.
14 15 16 |
# File 'lib/rails_admin/config/fields/base.rb', line 14 def defined @defined end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/rails_admin/config/fields/base.rb', line 13 def name @name end |
#order ⇒ Object
Returns the value of attribute order.
14 15 16 |
# File 'lib/rails_admin/config/fields/base.rb', line 14 def order @order end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
13 14 15 |
# File 'lib/rails_admin/config/fields/base.rb', line 13 def properties @properties end |
#section ⇒ Object
Returns the value of attribute section.
14 15 16 |
# File 'lib/rails_admin/config/fields/base.rb', line 14 def section @section end |
Class Method Details
.inherited(klass) ⇒ Object
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def self.inherited(klass) klass.instance_variable_set("@view_helper", :text_field) end |
Instance Method Details
#_html_attributes ⇒ Object
268 269 270 |
# File 'lib/rails_admin/config/fields/base.rb', line 268 def _html_attributes html_attributes.merge(!default_value.nil? ? { :value => default_value } : {}) end |
#association? ⇒ Boolean
Is this an association
211 212 213 |
# File 'lib/rails_admin/config/fields/base.rb', line 211 def association? kind_of?(RailsAdmin::Config::Fields::Association) end |
#editable ⇒ Object
197 198 199 200 201 202 203 204 |
# File 'lib/rails_admin/config/fields/base.rb', line 197 def editable return false if @properties && @properties[:read_only] role = bindings[:view].controller.send(:_attr_accessible_role) klass = bindings[:object].class whitelist = klass.accessible_attributes(role).map(&:to_s) blacklist = klass.protected_attributes(role).map(&:to_s) !self.method_name.to_s.in?(blacklist) && (whitelist.any? ? self.method_name.to_s.in?(whitelist) : true) end |
#errors ⇒ Object
Reader for validation errors of the bound object
216 217 218 |
# File 'lib/rails_admin/config/fields/base.rb', line 216 def errors bindings[:object].errors[name] end |
#inverse_of ⇒ Object
260 261 262 |
# File 'lib/rails_admin/config/fields/base.rb', line 260 def inverse_of nil end |
#method_name ⇒ Object
264 265 266 |
# File 'lib/rails_admin/config/fields/base.rb', line 264 def method_name name end |
#nested_form ⇒ Object
Reader for nested attributes
256 257 258 |
# File 'lib/rails_admin/config/fields/base.rb', line 256 def nested_form false end |
#optional(state = nil, &block) ⇒ Object
Inverse accessor whether this field is required.
230 231 232 233 234 235 236 |
# File 'lib/rails_admin/config/fields/base.rb', line 230 def optional(state = nil, &block) if !state.nil? || block required state.nil? ? proc { false == (instance_eval &block) } : false == state else optional? end end |
#optional=(state) ⇒ Object
Writer to make field optional.
241 242 243 |
# File 'lib/rails_admin/config/fields/base.rb', line 241 def optional=(state) optional(state) end |
#optional? ⇒ Boolean
Reader whether field is optional.
223 224 225 |
# File 'lib/rails_admin/config/fields/base.rb', line 223 def optional? not required end |
#render ⇒ Object
206 207 208 |
# File 'lib/rails_admin/config/fields/base.rb', line 206 def render bindings[:view].render :partial => partial.to_s, :locals => {:field => self, :form => bindings[:form] } end |
#type ⇒ Object
Reader for field’s type
246 247 248 |
# File 'lib/rails_admin/config/fields/base.rb', line 246 def type @type ||= self.class.name.to_s.demodulize.underscore.to_sym end |
#type_css_class ⇒ Object
38 39 40 |
# File 'lib/rails_admin/config/fields/base.rb', line 38 def type_css_class "#{type}_type" end |
#value ⇒ Object
Reader for field’s value
251 252 253 |
# File 'lib/rails_admin/config/fields/base.rb', line 251 def value bindings[:object].safe_send(name) end |
#virtual? ⇒ Boolean
42 43 44 |
# File 'lib/rails_admin/config/fields/base.rb', line 42 def virtual? properties.blank? end |