diff --git a/Gemfile b/Gemfile index 3991c75a..649a6c81 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index cea41295..c5f235f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb index 2c7dc102..e95b8d26 100644 --- a/app/controllers/admin/links_controller.rb +++ b/app/controllers/admin/links_controller.rb @@ -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 diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index ffbdea88..1d79bc41 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -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 diff --git a/app/models/attribute_attr_model.rb b/app/models/attribute_attr_model.rb index daeeacfa..8e26d274 100644 --- a/app/models/attribute_attr_model.rb +++ b/app/models/attribute_attr_model.rb @@ -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 diff --git a/app/models/i18n_variable.rb b/app/models/i18n_variable.rb index 175218b3..a913a841 100644 --- a/app/models/i18n_variable.rb +++ b/app/models/i18n_variable.rb @@ -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 diff --git a/app/models/item.rb b/app/models/item.rb index 9593a344..5ecd30cd 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index b792361d..ce64c7ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_attribute_model.rb b/app/models/user_attribute_model.rb index 1817046a..eb102a0a 100644 --- a/app/models/user_attribute_model.rb +++ b/app/models/user_attribute_model.rb @@ -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 diff --git a/app/views/admin/user_attribute_models/_attribute_attr_model.html.erb b/app/views/admin/user_attribute_models/_attribute_attr_model.html.erb index 9a39248e..1a8ddea7 100644 --- a/app/views/admin/user_attribute_models/_attribute_attr_model.html.erb +++ b/app/views/admin/user_attribute_models/_attribute_attr_model.html.erb @@ -13,7 +13,7 @@ <%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
> <%= 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" %>
@@ -23,6 +23,7 @@ (<%= t(:delete) %>) <%= hidden_field_tag "user_attribute_model[attribute_attr_models][][should_destroy]", nil , :class => 'should_destroy' %> <%= f.hidden_field :id %> + <%= f.hidden_field :key %> <% end %> diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 06f07a25..e024a9e0 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -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 - \ No newline at end of file