mongoid rc_6 & fix bugs

This commit is contained in:
chris authored and ihower committed 2011-04-13 18:22:49 +08:00
1 parent f347b150cf
commit bda67684bd
11 files changed
+70 -24

No files matched your search

@@ -47,6 +47,7 @@ class Admin::LinksController < ApplicationController
def destroy
@link = Link.find(params[:id])
@link.destroy
@link.destroy_i18n_variable
redirect_to admin_items_url( :parent_id => @link.parent_id )
end
@@ -46,6 +46,7 @@ class Admin::PagesController < ApplicationController
def destroy
@page = Page.find(params[:id])
@page.destroy
@page.destroy_i18n_variable
redirect_to admin_items_url( :parent_id => @page.parent_id )
end
+7 -7
View File
@@ -6,7 +6,7 @@ class AttributeAttrModel
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
field :markup
field :locale, :type => Boolean
field :options, :type => Array
field :list_options, :type => Array
embedded_in :user_attribute_model, :inverse_of => :attribute_attr_models
validates_uniqueness_of :key
@@ -32,14 +32,14 @@ class AttributeAttrModel
end
end
# Convert the string options into an array
def select_options=(var)
self.options = var.gsub(' ', '').split(',')
# Convert the string list_options into an array
def select_list_options=(var)
self.list_options = var.gsub(' ', '').split(',')
end
# Convert the array options into a string
def select_options
self.options.to_a.join(', ')
# Convert the array list_options into a string
def select_list_options
self.list_options.to_a.join(', ')
end
# Check if the attribute_attr is set to be destroyed
+2 -2
View File
@@ -3,7 +3,7 @@ class I18nVariable
include Mongoid::Document
field :key
field :document_class
field :parent_id, :index => true
field :document_class, :type => String
field :parent_id, :type => BSON::ObjectId, :index => true
end
+10
View File
@@ -21,6 +21,11 @@ class Item
before_validation :setup_default_value
# Destroy the i18n_variable
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })
end
@@ -32,6 +37,11 @@ class Item
nodes.reverse
end
# Destroy the i18n_variable
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
# Update or create the i18n_variable record
def i18n_variable=(attr)
if self.i18n_variable_id
+2 -2
View File
@@ -13,8 +13,8 @@ class User
before_update :clean_active_attributes
# Update or create the user_attribute records
def user_attributes=(attrs)
attrs.each do |attributes|
def user_attributes=(*attrs)
attrs[0].each do |attributes|
if attributes[:id].blank?
user_attributes.build(attributes)
else
+3 -2
View File
@@ -10,8 +10,8 @@ class UserAttributeModel
after_update :destroy_attrs
# Update or create the attribute_attr_model records
def attribute_attr_models=(attrs)
attrs.each do |attributes|
def attribute_attr_models=(*attrs)
attrs[0].each do |attributes|
if attributes[:id].blank?
attribute_attr_models.build(attributes)
else
@@ -52,6 +52,7 @@ class UserAttributeModel
attribute_attr_models.each do |a|
if a.should_destroy?
a.destroy
a.destroy_i18n_variable
end
end
end
@@ -13,7 +13,7 @@
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
<div <%= attribute_attr_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
<%= t('admin.options') %>:
<%= text_field_tag "user_attribute_model[attribute_attr_models][][select_options]", attribute_attr_model.select_options, :style => "width:130px" %>
<%= text_field_tag "user_attribute_model[attribute_attr_models][][select_list_options]", attribute_attr_model.select_list_options, :style => "width:130px" %>
</div>
</td>
<td>
@@ -23,6 +23,7 @@
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][should_destroy]", nil , :class => 'should_destroy' %>
<%= f.hidden_field :id %>
<%= f.hidden_field :key %>
<% end %>
</td>
</tr>