app/models/constructor_pages/field.rb in constructor-pages-0.3.0 vs app/models/constructor_pages/field.rb in constructor-pages-0.3.1
- old
+ new
@@ -7,12 +7,12 @@
validate :method_uniqueness
validates_uniqueness_of :code_name, :scope => :template_id
- after_create :create_page_field
- after_destroy :destroy_page_field
+ after_create :create_page_fields
+ after_destroy :destroy_page_fields
belongs_to :template
has_one :string_type, :class_name => "Types::StringType"
has_one :integer_type, :class_name => "Types::IntegerType"
@@ -27,29 +27,30 @@
default_scope :order => :position
private
def method_uniqueness
- if Page.first.respond_to?(code_name.pluralize) \
+ if Page.first.respond_to?(code_name) \
+ or Page.first.respond_to?(code_name.pluralize) \
or Page.first.respond_to?(code_name.singularize) \
- or template.self_and_ancestors.map{|t| t.code_name}.include?(code_name.pluralize) \
- or template.self_and_ancestors.map{|t| t.code_name}.include?(code_name.singularize) \
- or template.descendants.map{|t| t.code_name}.include?(code_name.pluralize) \
- or template.descendants.map{|t| t.code_name}.include?(code_name.singularize)
+ or template.self_and_ancestors.map{|t| t.code_name unless t.code_name == code_name}.include?(code_name.pluralize) \
+ or template.self_and_ancestors.map{|t| t.code_name t.code_name == code_name}.include?(code_name.singularize) \
+ or template.descendants.map{|t| t.code_name t.code_name == code_name}.include?(code_name.pluralize) \
+ or template.descendants.map{|t| t.code_name t.code_name == code_name}.include?(code_name.singularize)
errors.add(:base, "Такой метод уже используется")
end
end
- def create_page_field
+ def create_page_fields
self.template.pages.each do |page|
"constructor_pages/types/#{type_value}_type".classify.constantize.create(
:page_id => page.id,
:field_id => id
)
end
end
- def destroy_page_field
+ def destroy_page_fields
self.template.pages.each do |page|
"constructor_pages/types/#{type_value}_type".classify.constantize.destroy_all(
:page_id => page.id,
:field_id => id
)
\ No newline at end of file