mongoid rc_6 & fix bugs

This commit is contained in:
chris 2011-01-28 14:44:08 +08:00 committed by ihower
parent f347b150cf
commit bda67684bd
11 changed files with 70 additions and 24 deletions

View File

@ -7,7 +7,7 @@ gem 'carrierwave'
gem 'devise'
gem 'liquid'
gem 'mini_magick'
gem 'mongoid', '2.0.0.beta.20'
gem 'mongoid', '2.0.0.rc.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

View File

@ -30,7 +30,7 @@ GEM
activesupport (3.0.3)
arel (2.0.7)
bcrypt-ruby (2.1.4)
bson (1.1.5)
bson (1.2.0)
bson_ext (1.1.5)
builder (2.1.2)
carrierwave (0.5.1)
@ -50,11 +50,11 @@ GEM
mime-types (1.16)
mini_magick (3.2)
subexec (~> 0.0.4)
mongo (1.1.5)
bson (>= 1.1.5)
mongoid (2.0.0.beta.20)
mongo (1.2.0)
bson (>= 1.2.0)
mongoid (2.0.0.rc.6)
activemodel (~> 3.0)
mongo (~> 1.1)
mongo (~> 1.2)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
polyglot (0.3.1)
@ -95,5 +95,5 @@ DEPENDENCIES
devise
liquid
mini_magick
mongoid (= 2.0.0.beta.20)
mongoid (= 2.0.0.rc.6)
rails (= 3.0.3)

View File

@ -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

View File

@ -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

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

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

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

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

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

View File

@ -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>

View File

@ -1,10 +1,42 @@
# encoding: utf-8
namespace :dev do
task :build => :environment do
User.delete_all
[Item, Layout, Site, Snippet, User, UserAttributeModel].each { |m| m.delete_all }
User.create!( :email => 'chris@rulingcom.com', :password => 'password', :password_confirmation => 'password', :use_attributes => ["teacher"] )
User.create!( :email => 'chris@rulingcom.com',
:password => 'password',
:password_confirmation => 'password',
:admin => true,
:active_attributes => ["teacher"],
:user_attributes => [
{:key => 'teacher'}])
Home.create!( :type => "Home",
:content => "This is the home page\r\n{% t bob %}",
:full_name => "home",
:is_published => true,"layout_id" : ObjectId("4d23dadf5b0bad0b1100000e"), "layout_name" : "root", "name" : "home", "parent_id" : null, "parent_name" : null, "position" : 1, "title_en" : "Homepage", "title_zh_tw" : "首頁"
Layout.create!( :name => 'root', :description => 'root', :content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.layout.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/root.layout.en").read)
Page.create!( :name => "root", :title => I18n.t(:homepage), :layout_name => "root", :parent_name => nil,
:content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.page.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/root.page.en").read )
["about"].each do |page_name|
Page.create!( :name => page_name, :title => page_name, :layout_name => "root", :parent_name => "root",
:content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.page.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.page.en").read )
end
["nav", "footer", "locale"].each do |page_name|
Snippet.create!( :name => page_name, :parent_name => "root",
:content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.snippet.zh_tw").read,
:content_en => File.open("#{RAILS_ROOT}/lib/template/#{page_name}.snippet.en").read )
end
end
end