Fix bug: users can now be saved

This commit is contained in:
chris2tof 2011-11-12 17:54:45 +08:00
parent 0a6efeb0a2
commit d9d7099da6
7 changed files with 26 additions and 18 deletions

View File

@ -0,0 +1,12 @@
module Panel::UserHelper
def show_user_attribute(object, key, locale = '')
attribute = object.attribute_values.detect {|av| av.key.to_s.eql?(key.to_s) || av[locale.to_s].eql?(locale.to_s) }
if locale.to_s.blank?
attribute['key']
else
attribute[locale.to_s]
end
end
end

View File

@ -11,7 +11,7 @@ class AttributeModel
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
embedded_in :user_attribute_model, :inverse_of => :attribute_models
embedded_in :user_attribute_model
validates_uniqueness_of :key
# Destroy the i18n_variable

View File

@ -7,7 +7,7 @@ class UserAttribute
has_many :attribute_values
# Update or create the attribute_value records
def attributes=(*args)
def attribute_values=(*args)
args[0].each do |value|
if value[:id].blank?
attribute_values.build(value)

View File

@ -6,9 +6,9 @@
<td><%= attr.i18n_variable[I18n.locale] %></td>
<td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= show_user_attribute["#{attr.key}_#{I18n.locale}"] rescue nil %>
<%= show_user_attribute(object, attr.key, I18n.locale) %>
<% else %>
<%= show_user_attribute["#{attr.key}"] rescue nil %>
<%= show_user_attribute(object, attr.key) %>
<% end %>
</td>
</tr>

View File

@ -14,23 +14,23 @@
<% ua.get_enabled_attribute_models.each do |attr| %>
<% value = user_attribute.attribute_values.detect{|v| v.key == attr.key } %>
<%= hidden_field_tag "user[user_#{type}s][][attributes][][id]", value.id rescue nil %>
<%= hidden_field_tag "user[user_#{type}s][][attributes][][key]", attr.key %>
<%= hidden_field_tag "user[user_#{type}s][][attribute_values][][id]", value.id rescue nil %>
<%= hidden_field_tag "user[user_#{type}s][][attribute_values][][key]", attr.key %>
<tr>
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= hidden_field_tag "user[user_#{type}s][][attributes][][non_locale]", nil %>
<%= hidden_field_tag "user[user_#{type}s][][attribute_values][][non_locale]", nil %>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user[user_#{type}s][][attributes][][#{locale}]", (value[locale] rescue nil) %>
<%= text_field_tag "user[user_#{type}s][][attribute_values][][#{locale}]", (value[locale] rescue nil) %>
</td>
<% end -%>
<% else %>
<td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %>
<%= text_field_tag "user[user_#{type}s][][attributes][][non_locale]", (value['non_locale'] rescue nil) %>
<%= text_field_tag "user[user_#{type}s][][attribute_values][][non_locale]", (value['non_locale'] rescue nil) %>
<% elsif attr["markup"] == "select" %>
<%= select_tag "user[user_#{type}s][][attributes][][non_locale]", options_for_select(attr["options"], value['non_locale']) %>
<%= select_tag "user[user_#{type}s][][attribute_values][][non_locale]", options_for_select(attr["options"], value['non_locale']) %>
<% end -%>
</td>
<% end -%>

View File

@ -14,9 +14,7 @@
<fieldset>
<legend><%= t('panel.infos') %></legend>
<% @user_info_models.each do |am| %>
<%= render :partial => 'show_user_attribute',
:object => @user.get_info_from_model_key(am.key),
:locals => {:am => am} %>
<%= render :partial => 'show_user_attribute', :locals => {:am => am, :object => @user.get_info_from_model_key(am.key)} %>
<% end -%>
</fieldset>
<% end %>
@ -25,9 +23,7 @@
<fieldset>
<legend><%= t('panel.roles') %></legend>
<% @user.get_active_role_models.each do |am| %>
<%= render :partial => 'show_user_attribute',
:object => @user.get_role_from_model_key(am.key),
:locals => {:am => am} %>
<%= render :partial => 'show_user_attribute', :locals => {:am => am, :object => @user.get_role_from_model_key(am.key)} %>
<% end -%>
</fieldset>
<% end %>

View File

@ -31,8 +31,8 @@ class CentralServerExchangeApp < Sinatra::Base
post '/purchase/design' do
begin
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase']))
design.save
p_design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase']))
p_design.save
body 'true'
rescue
body 'false'