diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb index 1a0123b2..4fd14c49 100644 --- a/app/controllers/panel/users_controller.rb +++ b/app/controllers/panel/users_controller.rb @@ -13,6 +13,7 @@ class Panel::UsersController < ApplicationController def new @user = User.new + @user_attributes = UserAttribute.all end def create @@ -26,6 +27,7 @@ class Panel::UsersController < ApplicationController def edit @user = User.find(params[:id]) + @user_attributes = UserAttribute.all end def update diff --git a/app/models/user.rb b/app/models/user.rb index 3cd89648..478f2588 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,16 @@ class User devise :authenticatable, :recoverable, :rememberable, :trackable - key :use_attributes - + # key :use_attributes + + def method_missing(method) + safe_read(method) + end + + def safe_read(key) + self[key] + rescue MongoMapper::KeyNotFound + return "" + end + end \ No newline at end of file diff --git a/app/models/user_attribute.rb b/app/models/user_attribute.rb index 92e8aba3..005dfecf 100644 --- a/app/models/user_attribute.rb +++ b/app/models/user_attribute.rb @@ -2,7 +2,7 @@ class UserAttribute include MongoMapper::Document - key :ident, String + key :key, String key_i18n :name, String key_i18n :attrs, Array diff --git a/app/views/panel/users/_form.html.erb b/app/views/panel/users/_form.html.erb index 65a98419..1be9e60e 100644 --- a/app/views/panel/users/_form.html.erb +++ b/app/views/panel/users/_form.html.erb @@ -1,7 +1,13 @@ -
- <%= label_tag :name %> - <%= text_field_tag "user[name]" %> -
+<% @user_attributes.each do |ua| %> ++ <%= f.label attr["name"] %> + <%= f.send(attr["type"], "#{ua.key}_#{attr["key"]}" )%> +
+ <% end -%> +<% end -%><%= f.label :email %> diff --git a/app/views/panel/users/index.html.erb b/app/views/panel/users/index.html.erb index 0065539a..9187c6e7 100644 --- a/app/views/panel/users/index.html.erb +++ b/app/views/panel/users/index.html.erb @@ -17,7 +17,7 @@ <% @users.each do |user| %>