From d0c2856a3ab4d22bf53711d652e7bcb32f217d35 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Wed, 15 Feb 2012 11:42:19 +0800 Subject: [PATCH] Fix relations error in tags --- app/controllers/admin/tags_controller.rb | 2 +- app/models/i18n_variable.rb | 4 ---- app/models/tag.rb | 1 - app/views/admin/tags/_form.html.erb | 2 +- vendor/built_in_modules/announcement/app/models/bulletin.rb | 2 +- .../announcement/app/models/module_app_tag.rb | 5 +++++ 6 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 vendor/built_in_modules/announcement/app/models/module_app_tag.rb diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index ef1e1118..749b21ac 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -19,7 +19,7 @@ class Admin::TagsController < ApplicationController end def create - @tag = Tag.create(params[:tag]) + @tag = (params[:tag][:module_app_id].blank? ? Tag.create(params[:tag]) : ModuleAppTag.create(params[:tag])) end def update diff --git a/app/models/i18n_variable.rb b/app/models/i18n_variable.rb index 1583d20e..563ba791 100644 --- a/app/models/i18n_variable.rb +++ b/app/models/i18n_variable.rb @@ -21,8 +21,4 @@ class I18nVariable I18nVariable.first(:conditions => {:key => locale})[I18n.locale] end - def self.from_locale(locale) - I18nVariable.first(:conditions => {:key => locale})[I18n.locale] - end - end diff --git a/app/models/tag.rb b/app/models/tag.rb index 0449896c..f77f24c1 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -4,6 +4,5 @@ class Tag include Mongoid::Timestamps belongs_to :module_app - has_and_belongs_to_many :bulletins end diff --git a/app/views/admin/tags/_form.html.erb b/app/views/admin/tags/_form.html.erb index 2ca42363..566e42ac 100644 --- a/app/views/admin/tags/_form.html.erb +++ b/app/views/admin/tags/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for tag, :url => admin_tag_path(tag), :remote => true do |f| %> +<%= form_for :tag, :url => admin_tag_path(tag), :method => :put, :remote => true do |f| %> <% @site_valid_locales.each do |locale| %> <%= I18nVariable.from_locale(locale) %>:<%= f.text_field locale %> <% end %> diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index e5ff381b..b4362b22 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -8,7 +8,7 @@ class Bulletin has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_one :subtitle, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy - has_and_belongs_to_many :tags + has_and_belongs_to_many :tags, :class_name => "ModuleAppTag" field :postdate , :type => Date field :deadline , :type => Date diff --git a/vendor/built_in_modules/announcement/app/models/module_app_tag.rb b/vendor/built_in_modules/announcement/app/models/module_app_tag.rb new file mode 100644 index 00000000..0ee739f9 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/models/module_app_tag.rb @@ -0,0 +1,5 @@ +class ModuleAppTag < Tag + + has_and_belongs_to_many :bulletins + +end \ No newline at end of file