mongoid fields are not shared by 2 instances of a same class but with different custom fields
This commit is contained in:
parent
1a2467acf4
commit
311903a43d
@ -1,7 +1,5 @@
|
||||
- highlighted_field_name = @content.content_type.highlighted_field_name
|
||||
|
||||
- puts "current custom fields = #{@content.custom_fields.inspect}"
|
||||
|
||||
= f.inputs :name => :other_fields do
|
||||
- @content.custom_fields.each do |field|
|
||||
- required = highlighted_field_name == field._name
|
||||
|
11
doc/TODO
11
doc/TODO
@ -1,11 +1,8 @@
|
||||
BOARD:
|
||||
- contents sub menu => BUG
|
||||
BOARD:
|
||||
- liquid rendering engine
|
||||
|
||||
BACKLOG:
|
||||
- liquid rendering engine
|
||||
- theme assets
|
||||
- assets collection
|
||||
- custom models
|
||||
- asset collections: custom resizing if image
|
||||
|
||||
- devise messages in French
|
||||
@ -18,6 +15,7 @@ BUGS:
|
||||
- theme assets: disable version if not image
|
||||
- assets uploader: remove old files if new one
|
||||
|
||||
|
||||
DONE:
|
||||
x admin layout
|
||||
x logout button
|
||||
@ -79,4 +77,5 @@ x content types / models (CRUD)
|
||||
x require a custom field at least
|
||||
x pre-select the first custom field as the highlighted one
|
||||
x contents (CRUD)
|
||||
x sort contents
|
||||
x sort contents
|
||||
x contents sub menu => BUG
|
@ -34,8 +34,12 @@ module CustomFields
|
||||
def apply(object, association_name)
|
||||
return unless self.valid?
|
||||
|
||||
object.class.send(:set_field, self._name, { :type => self.field_type })
|
||||
# trick mongoid
|
||||
object.class_eval { def meta; (class << self; self; end); end }
|
||||
object.meta.fields = object.fields.clone
|
||||
object.meta.send(:define_method, :fields) { self.meta.fields }
|
||||
|
||||
object.meta.field self._name, :type => self.field_type
|
||||
object.class_eval <<-EOF
|
||||
alias :#{self.safe_alias} :#{self._name}
|
||||
alias :#{self.safe_alias}= :#{self._name}=
|
||||
|
@ -5,16 +5,18 @@ module Mongoid #:nodoc:
|
||||
def parentize_with_custom_fields(object, association_name)
|
||||
parentize_without_custom_fields(object, association_name)
|
||||
|
||||
if self.custom_fields?(object, association_name)
|
||||
puts "[parentize_with_custom_fields] association_name = #{association_name} / #{self.custom_fields_association_name(association_name)}"
|
||||
self.class.send(:define_method, :custom_fields) do
|
||||
fields = object.send(self.custom_fields_association_name(association_name))
|
||||
fields.sort { |a, b| (a.position || 0) <=> (b.position || 0) }
|
||||
end
|
||||
|
||||
if self.custom_fields?(object, association_name)
|
||||
# puts "[parentize_with_custom_fields] association_name = #{association_name} / #{self.custom_fields_association_name(association_name)}"
|
||||
object.send(self.custom_fields_association_name(association_name)).each do |field|
|
||||
field.apply(self, association_name)
|
||||
end
|
||||
|
||||
self.instance_eval <<-EOV
|
||||
def custom_fields
|
||||
fields = self._parent.send(:#{self.custom_fields_association_name(association_name)})
|
||||
fields.sort { |a, b| (a.position || 0) <=> (b.position || 0) }
|
||||
end
|
||||
EOV
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user