From 4cdef7655083c5036946f591fd5cce909045c09d Mon Sep 17 00:00:00 2001 From: chris2tof Date: Fri, 13 Jan 2012 12:35:46 +0800 Subject: [PATCH 1/2] Update carrierwave #{column}_identifier must be used to get the name of the file --- Gemfile | 5 +++-- Gemfile.lock | 24 +++++++++++------------- config/initializers/carrierwave.rb | 6 +++--- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 4fe1340a..995de255 100644 --- a/Gemfile +++ b/Gemfile @@ -3,14 +3,15 @@ gem 'rails' gem 'yajl-ruby', :require => 'yajl' gem 'bson_ext' -gem 'carrierwave', '0.5.4' +gem 'carrierwave' +gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' gem 'ckeditor' gem 'devise' gem 'mini_magick' gem 'rubyzip' gem 'sinatra' gem 'execjs' -gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git', :ref => '7a915395db50e2bc6071a503a11530e644879e49' +gem 'mongoid' gem 'rake' gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index fcf8f0b9..f733511e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,3 @@ -GIT - remote: git://github.com/mongoid/mongoid.git - revision: 7a915395db50e2bc6071a503a11530e644879e49 - ref: 7a915395db50e2bc6071a503a11530e644879e49 - specs: - mongoid (2.4.0) - activemodel (~> 3.1) - mongo (~> 1.3) - tzinfo (~> 0.3.22) - GEM remote: http://rubygems.org/ specs: @@ -46,8 +36,11 @@ GEM bson_ext (1.5.2) bson (= 1.5.2) builder (3.0.0) - carrierwave (0.5.4) + carrierwave (0.5.8) activesupport (~> 3.0) + carrierwave-mongoid (0.1.3) + carrierwave (>= 0.5.6) + mongoid (~> 2.1) chronic (0.6.6) ckeditor (3.6.3) mime-types (~> 1.16) @@ -94,6 +87,10 @@ GEM subexec (~> 0.1.0) mongo (1.5.2) bson (= 1.5.2) + mongoid (2.4.0) + activemodel (~> 3.1) + mongo (~> 1.3) + tzinfo (~> 0.3.22) multi_json (1.0.4) orm_adapter (0.0.5) polyglot (0.3.3) @@ -190,7 +187,8 @@ PLATFORMS DEPENDENCIES bson_ext - carrierwave (= 0.5.4) + carrierwave + carrierwave-mongoid ckeditor coffee-rails database_cleaner @@ -200,7 +198,7 @@ DEPENDENCIES factory_girl_rails jquery-rails mini_magick - mongoid! + mongoid radius rails rake diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 1c7f73c1..2c46dd11 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,5 +1,3 @@ -require 'carrierwave/orm/mongoid' - begin db_config = YAML::load(File.read(File.join(Rails.root, "/config/mongoid.yml"))) rescue @@ -12,4 +10,6 @@ CarrierWave.configure do |config| config.grid_fs_port = db_config[Rails.env]['port'] config.storage = :grid_fs config.grid_fs_access_url = "/gridfs" -end \ No newline at end of file +end + +CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ From f86777b617cf53c411aa961963e6e00752192bd8 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 16 Jan 2012 08:14:05 +0800 Subject: [PATCH 2/2] Embed attribute_fields and sub_roles --- app/models/user/attribute.rb | 2 +- app/models/user/attribute_field.rb | 2 +- app/models/user/role.rb | 2 +- app/models/user/sub_role.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user/attribute.rb b/app/models/user/attribute.rb index af8a1106..84650421 100644 --- a/app/models/user/attribute.rb +++ b/app/models/user/attribute.rb @@ -7,7 +7,7 @@ class Attribute field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - has_many :attribute_fields, :autosave => true, :dependent => :destroy + embeds_many :attribute_fields, :cascade_callbacks => true has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :attribute_fields, :allow_destroy => true diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index 42bbf910..2d909b3e 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -10,7 +10,7 @@ class AttributeField field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - belongs_to :attribute + embedded_in :attribute has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :attribute_values diff --git a/app/models/user/role.rb b/app/models/user/role.rb index 86f7266f..788d281d 100644 --- a/app/models/user/role.rb +++ b/app/models/user/role.rb @@ -7,7 +7,7 @@ class Role field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - has_many :sub_roles, :autosave => true, :dependent => :destroy + embeds_many :sub_roles, :cascade_callbacks => true has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :users accepts_nested_attributes_for :i18n_variable, :allow_destroy => true diff --git a/app/models/user/sub_role.rb b/app/models/user/sub_role.rb index cdefb5f5..47f3e2de 100644 --- a/app/models/user/sub_role.rb +++ b/app/models/user/sub_role.rb @@ -1,6 +1,6 @@ class SubRole < Attribute - belongs_to :role + embedded_in :role has_and_belongs_to_many :users # Get an sub_role from key