mongoid rc_6 & fix bugs
This commit is contained in:
parent
f347b150cf
commit
bda67684bd
2
Gemfile
2
Gemfile
|
@ -7,7 +7,7 @@ gem 'carrierwave'
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'liquid'
|
gem 'liquid'
|
||||||
gem 'mini_magick'
|
gem 'mini_magick'
|
||||||
gem 'mongoid', '2.0.0.beta.20'
|
gem 'mongoid', '2.0.0.rc.6'
|
||||||
|
|
||||||
# Bundle edge Rails instead:
|
# Bundle edge Rails instead:
|
||||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -30,7 +30,7 @@ GEM
|
||||||
activesupport (3.0.3)
|
activesupport (3.0.3)
|
||||||
arel (2.0.7)
|
arel (2.0.7)
|
||||||
bcrypt-ruby (2.1.4)
|
bcrypt-ruby (2.1.4)
|
||||||
bson (1.1.5)
|
bson (1.2.0)
|
||||||
bson_ext (1.1.5)
|
bson_ext (1.1.5)
|
||||||
builder (2.1.2)
|
builder (2.1.2)
|
||||||
carrierwave (0.5.1)
|
carrierwave (0.5.1)
|
||||||
|
@ -50,11 +50,11 @@ GEM
|
||||||
mime-types (1.16)
|
mime-types (1.16)
|
||||||
mini_magick (3.2)
|
mini_magick (3.2)
|
||||||
subexec (~> 0.0.4)
|
subexec (~> 0.0.4)
|
||||||
mongo (1.1.5)
|
mongo (1.2.0)
|
||||||
bson (>= 1.1.5)
|
bson (>= 1.2.0)
|
||||||
mongoid (2.0.0.beta.20)
|
mongoid (2.0.0.rc.6)
|
||||||
activemodel (~> 3.0)
|
activemodel (~> 3.0)
|
||||||
mongo (~> 1.1)
|
mongo (~> 1.2)
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
will_paginate (~> 3.0.pre)
|
will_paginate (~> 3.0.pre)
|
||||||
polyglot (0.3.1)
|
polyglot (0.3.1)
|
||||||
|
@ -95,5 +95,5 @@ DEPENDENCIES
|
||||||
devise
|
devise
|
||||||
liquid
|
liquid
|
||||||
mini_magick
|
mini_magick
|
||||||
mongoid (= 2.0.0.beta.20)
|
mongoid (= 2.0.0.rc.6)
|
||||||
rails (= 3.0.3)
|
rails (= 3.0.3)
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Admin::LinksController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@link = Link.find(params[:id])
|
@link = Link.find(params[:id])
|
||||||
@link.destroy
|
@link.destroy
|
||||||
|
@link.destroy_i18n_variable
|
||||||
|
|
||||||
redirect_to admin_items_url( :parent_id => @link.parent_id )
|
redirect_to admin_items_url( :parent_id => @link.parent_id )
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,6 +46,7 @@ class Admin::PagesController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
@page.destroy
|
@page.destroy
|
||||||
|
@page.destroy_i18n_variable
|
||||||
|
|
||||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class AttributeAttrModel
|
||||||
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
||||||
field :markup
|
field :markup
|
||||||
field :locale, :type => Boolean
|
field :locale, :type => Boolean
|
||||||
field :options, :type => Array
|
field :list_options, :type => Array
|
||||||
|
|
||||||
embedded_in :user_attribute_model, :inverse_of => :attribute_attr_models
|
embedded_in :user_attribute_model, :inverse_of => :attribute_attr_models
|
||||||
validates_uniqueness_of :key
|
validates_uniqueness_of :key
|
||||||
|
@ -32,14 +32,14 @@ class AttributeAttrModel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert the string options into an array
|
# Convert the string list_options into an array
|
||||||
def select_options=(var)
|
def select_list_options=(var)
|
||||||
self.options = var.gsub(' ', '').split(',')
|
self.list_options = var.gsub(' ', '').split(',')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert the array options into a string
|
# Convert the array list_options into a string
|
||||||
def select_options
|
def select_list_options
|
||||||
self.options.to_a.join(', ')
|
self.list_options.to_a.join(', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if the attribute_attr is set to be destroyed
|
# Check if the attribute_attr is set to be destroyed
|
||||||
|
|
|
@ -3,7 +3,7 @@ class I18nVariable
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
|
|
||||||
field :key
|
field :key
|
||||||
field :document_class
|
field :document_class, :type => String
|
||||||
field :parent_id, :index => true
|
field :parent_id, :type => BSON::ObjectId, :index => true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,6 +21,11 @@ class Item
|
||||||
|
|
||||||
before_validation :setup_default_value
|
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)
|
def self.find_by_name(item_name)
|
||||||
Item.first(:conditions => { :name => item_name, :is_published => true })
|
Item.first(:conditions => { :name => item_name, :is_published => true })
|
||||||
end
|
end
|
||||||
|
@ -32,6 +37,11 @@ class Item
|
||||||
nodes.reverse
|
nodes.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Destroy the i18n_variable
|
||||||
|
def destroy_i18n_variable
|
||||||
|
self.i18n_variable.destroy rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
# Update or create the i18n_variable record
|
# Update or create the i18n_variable record
|
||||||
def i18n_variable=(attr)
|
def i18n_variable=(attr)
|
||||||
if self.i18n_variable_id
|
if self.i18n_variable_id
|
||||||
|
|
|
@ -13,8 +13,8 @@ class User
|
||||||
before_update :clean_active_attributes
|
before_update :clean_active_attributes
|
||||||
|
|
||||||
# Update or create the user_attribute records
|
# Update or create the user_attribute records
|
||||||
def user_attributes=(attrs)
|
def user_attributes=(*attrs)
|
||||||
attrs.each do |attributes|
|
attrs[0].each do |attributes|
|
||||||
if attributes[:id].blank?
|
if attributes[:id].blank?
|
||||||
user_attributes.build(attributes)
|
user_attributes.build(attributes)
|
||||||
else
|
else
|
||||||
|
|
|
@ -10,8 +10,8 @@ class UserAttributeModel
|
||||||
after_update :destroy_attrs
|
after_update :destroy_attrs
|
||||||
|
|
||||||
# Update or create the attribute_attr_model records
|
# Update or create the attribute_attr_model records
|
||||||
def attribute_attr_models=(attrs)
|
def attribute_attr_models=(*attrs)
|
||||||
attrs.each do |attributes|
|
attrs[0].each do |attributes|
|
||||||
if attributes[:id].blank?
|
if attributes[:id].blank?
|
||||||
attribute_attr_models.build(attributes)
|
attribute_attr_models.build(attributes)
|
||||||
else
|
else
|
||||||
|
@ -52,6 +52,7 @@ class UserAttributeModel
|
||||||
attribute_attr_models.each do |a|
|
attribute_attr_models.each do |a|
|
||||||
if a.should_destroy?
|
if a.should_destroy?
|
||||||
a.destroy
|
a.destroy
|
||||||
|
a.destroy_i18n_variable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
|
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
|
||||||
<div <%= attribute_attr_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
|
<div <%= attribute_attr_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
|
||||||
<%= t('admin.options') %>:
|
<%= 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>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -23,6 +23,7 @@
|
||||||
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
|
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
|
||||||
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][should_destroy]", nil , :class => 'should_destroy' %>
|
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][should_destroy]", nil , :class => 'should_destroy' %>
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
|
<%= f.hidden_field :key %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,10 +1,42 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
namespace :dev do
|
namespace :dev do
|
||||||
|
|
||||||
task :build => :environment 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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue