Fix mongoid deeply nested polimorphic
Got the commit from github. The roles and sub_roles save.
This commit is contained in:
parent
d27d7a623c
commit
4108ebf06d
2
Gemfile
2
Gemfile
|
@ -10,7 +10,7 @@ gem 'mini_magick'
|
|||
gem 'rubyzip'
|
||||
gem 'sinatra'
|
||||
gem 'execjs'
|
||||
gem 'mongoid'
|
||||
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git', :ref => '7a915395db50e2bc6071a503a11530e644879e49'
|
||||
|
||||
gem 'rake'
|
||||
gem 'jquery-rails'
|
||||
|
|
22
Gemfile.lock
22
Gemfile.lock
|
@ -1,3 +1,13 @@
|
|||
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:
|
||||
|
@ -32,7 +42,7 @@ GEM
|
|||
archive-tar-minitar (0.5.2)
|
||||
arel (2.2.1)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bson (1.5.1)
|
||||
bson (1.5.2)
|
||||
bson_ext (1.5.1)
|
||||
builder (3.0.0)
|
||||
carrierwave (0.5.4)
|
||||
|
@ -80,12 +90,8 @@ GEM
|
|||
mime-types (1.17.2)
|
||||
mini_magick (3.3)
|
||||
subexec (~> 0.1.0)
|
||||
mongo (1.5.1)
|
||||
bson (= 1.5.1)
|
||||
mongoid (2.3.4)
|
||||
activemodel (~> 3.1)
|
||||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
mongo (1.5.2)
|
||||
bson (= 1.5.2)
|
||||
multi_json (1.0.4)
|
||||
orm_adapter (0.0.5)
|
||||
polyglot (0.3.3)
|
||||
|
@ -190,7 +196,7 @@ DEPENDENCIES
|
|||
factory_girl_rails
|
||||
jquery-rails
|
||||
mini_magick
|
||||
mongoid
|
||||
mongoid!
|
||||
rails
|
||||
rake
|
||||
rcov
|
||||
|
|
|
@ -2,12 +2,12 @@ $('.attributes_block a.delete').live('click', function(){
|
|||
$(this).parents('.list_item').remove();
|
||||
});
|
||||
|
||||
$('#attributes a.remove_existing_record').live('click', function(){
|
||||
$('.action a.remove_existing_record').live('click', function(){
|
||||
$(this).next('.should_destroy').attr('value', 1);
|
||||
$("#attribute_" + $(this).prev().attr('value')).hide();
|
||||
});
|
||||
|
||||
$('#attributes_block a.switch').live('click', function(){
|
||||
$('.action a.switch').live('click', function(){
|
||||
$(this).parent().toggleClass('disable');
|
||||
var $am = $(this).next('.built_in_state')
|
||||
$am.attr('value', ($am.attr('value') == "false") ? "true" : "false");
|
||||
|
|
|
@ -26,12 +26,14 @@ class Admin::RolesController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
puts params.to_yaml
|
||||
@attribute = Role.new(params[:role])
|
||||
@attribute.save
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
||||
def update
|
||||
puts params.to_yaml
|
||||
@attribute = Role.find(params[:id])
|
||||
@attribute.update_attributes(params[:role])
|
||||
respond_to do |format|
|
||||
|
|
|
@ -9,7 +9,6 @@ class Attribute
|
|||
|
||||
has_many :attribute_fields, :autosave => true, :dependent => :destroy
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
|
||||
|
||||
def is_built_in?
|
||||
|
|
|
@ -13,8 +13,8 @@ class AttributeField
|
|||
belongs_to :attribute
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_many :attribute_values
|
||||
|
||||
validates_uniqueness_of :key
|
||||
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||
|
||||
# Convert the string list_options into an array
|
||||
def select_list_options=(var)
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
<td class='select_mulitlingual' style='text-align:center'>
|
||||
<%= f.check_box :locale %>
|
||||
</td>
|
||||
<%= f.fields_for :i18n_variable, (attribute_field.i18n_variable.nil? ? attribute_field.build_i18n_variable : attribute_field.i18n_variable) do |f| %>
|
||||
<%= f.fields_for :i18n_variable, (attribute_field.new_record? ? attribute_field.build_i18n_variable : attribute_field.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td><%= f.text_field locale, :style => "width:130px" %></td>
|
||||
<% end %>
|
||||
<%= f.hidden_field :id %>
|
||||
<% end %>
|
||||
<td class='select_type'>
|
||||
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
<tbody>
|
||||
<tr class="list_item">
|
||||
<td><%= is_new ? (f.text_field :key, {:style => "width:150px"}) : @attribute.key %></td>
|
||||
<%= f.fields_for :i18n_variable, (@attribute.new_record? ? @attribute.build_i18n_variable : @attribute.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td>
|
||||
<%= text_field_tag "#{@attribute_type}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||
</td>
|
||||
<td><%= f.text_field locale, :style => "width:150px" %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
<tbody>
|
||||
<tr class="list_item">
|
||||
<td><%= is_new ? (f.text_field :key, {:style => "width:150px"}) : @attribute.key %></td>
|
||||
<%= f.fields_for :i18n_variable, (@attribute.new_record? ? @attribute.build_i18n_variable : @attribute.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td>
|
||||
<%= text_field_tag "#{@attribute_type}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||
</td>
|
||||
<td><%= f.text_field locale, :style => "width:150px" %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -26,8 +26,8 @@
|
|||
|
||||
<div id='sub_roles' class="attributes_block <%= @class %>">
|
||||
<h2>Sub roles</h2>
|
||||
<% @attribute.sub_roles.each do |sub_role| %>
|
||||
<%= render :partial => 'form_sub', :object => sub_role, :locals => {:f => f} %>
|
||||
<% @attribute.sub_roles.each_with_index do |sub_role, i| %>
|
||||
<%= render :partial => 'form_sub', :object => sub_role, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -38,12 +38,12 @@
|
|||
</div>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "attribute_form" %>
|
||||
<script>
|
||||
$('#add_sub_role a.add').live('click', function(){
|
||||
var new_id = $(this).prev().attr('value');
|
||||
var old_id = new RegExp("new_sub_roles", "g");
|
||||
$(this).prev().attr('value', parseInt(new_id) + 1);
|
||||
$('#sub_role_temp_id').attr('value', new_id);
|
||||
$('#sub_roles').append(("<%= escape_javascript(add_attribute 'admin/roles/sub_role', f, :sub_roles) %>").replace(old_id, new_id));
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<%= f.fields_for :sub_roles, form_sub do |f| %>
|
||||
<%= render :partial => 'sub_role', :object => form_sub, :locals => {:f => f} %>
|
||||
<%= render :partial => 'sub_role', :object => form_sub, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
|
@ -12,10 +12,10 @@
|
|||
<tbody>
|
||||
<tr class="list_item">
|
||||
<td><%= sub_role.new_record? ? (f.text_field :key, {:style => "width:150px"}) : sub_role.key %></td>
|
||||
<%= f.fields_for :i18n_variable, (sub_role.new_record? ? sub_role.build_i18n_variable : sub_role.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<td>
|
||||
<%= f.text_field "i18n_variable[#{locale}]", :value => (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||
</td>
|
||||
<td><%= f.text_field locale, :style => "width:150px" %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -37,10 +37,10 @@
|
|||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<td id='add_attribute' colspan="5">
|
||||
<%= hidden_field_tag 'attribute_field_count', sub_role.attribute_fields.count %>
|
||||
<a href="#" class="add"><%= t(:add) %></a>
|
||||
<%= hidden_field_tag 'sub_role_temp_id', 'new_sub_roles' %>
|
||||
<%= hidden_field_tag 'sub_role_temp_id', (i rescue 'new_sub_roles') %>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
@ -55,16 +55,14 @@
|
|||
</div>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "attribute_form" %>
|
||||
<script>
|
||||
$('.attributes_block a.add').live('click', function(){
|
||||
$('#add_attribute a.add').live('click', function(){
|
||||
var new_parent_id = $(this).next().attr('value');
|
||||
var old_parent_id = new RegExp("new_sub_roles", "g");
|
||||
var new_id = $(this).prev().attr('value');
|
||||
var old_id = new RegExp("new_attribute_fields", "g");
|
||||
$(this).prev().attr('value', parseInt(new_id) + 1);
|
||||
$(this).next().attr('value', parseInt(new_parent_id) + 1);
|
||||
$(this).parents('.sub_role_attributes').append(("<%= escape_javascript(add_attribute 'admin/attributes/attribute_field', f, :attribute_fields) %>").replace(old_id, new_id).replace(old_parent_id, new_parent_id));
|
||||
$(this).parents('table').append(("<%= escape_javascript(add_attribute 'admin/attributes/attribute_field', f, :attribute_fields) %>").replace(old_id, new_id).replace(old_parent_id, new_parent_id));
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
<% end unless !sub_role.new_record? %>
|
Loading…
Reference in New Issue