From 9f1de1b5432702dfaf1bad269bdd0bcc6bccf1b5 Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Thu, 4 Mar 2010 17:11:18 +0800 Subject: [PATCH] Add UserAttribute model, suppose it will store user model want to use which attribute group --- app/models/user.rb | 2 ++ app/models/user_attribute.rb | 9 +++++++++ app/views/panel/users/index.html.erb | 9 +++++++-- app/views/panel/users/show.html.erb | 10 ++++++++++ lib/tasks/dev.rake | 5 ++++- 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/models/user_attribute.rb create mode 100644 app/views/panel/users/show.html.erb diff --git a/app/models/user.rb b/app/models/user.rb index 5ce3f0d8c..3cd89648c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,6 @@ class User devise :authenticatable, :recoverable, :rememberable, :trackable + key :use_attributes + end \ No newline at end of file diff --git a/app/models/user_attribute.rb b/app/models/user_attribute.rb new file mode 100644 index 000000000..92e8aba30 --- /dev/null +++ b/app/models/user_attribute.rb @@ -0,0 +1,9 @@ +class UserAttribute + + include MongoMapper::Document + + key :ident, String + key_i18n :name, String + key_i18n :attrs, Array + +end \ No newline at end of file diff --git a/app/views/panel/users/index.html.erb b/app/views/panel/users/index.html.erb index 4fcdbd680..0065539a6 100644 --- a/app/views/panel/users/index.html.erb +++ b/app/views/panel/users/index.html.erb @@ -8,16 +8,21 @@ - + + <% @users.each do |user| %> + - + <% end %>
NameAttrsName Email Action
<%= user.use_attributes.join(",") %> <%#= user.name %> <%= user.email %><%= link_to 'Edit', edit_panel_user_path(user) %> | <%= link_to 'Destroy', panel_user_path(user), :method => :delete %> + <%= link_to 'Show', panel_user_path(user) %> + <%= link_to 'Edit', edit_panel_user_path(user) %> | + <%= link_to 'Destroy', panel_user_path(user), :method => :delete %>
diff --git a/app/views/panel/users/show.html.erb b/app/views/panel/users/show.html.erb new file mode 100644 index 000000000..fb30564fb --- /dev/null +++ b/app/views/panel/users/show.html.erb @@ -0,0 +1,10 @@ +<% content_for :secondary do %> + +<% end -%> + +

Users panel

+ +<%=h @user.name %> +<%=h @user.email %> \ No newline at end of file diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 90aa3de7c..71809b860 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -2,7 +2,10 @@ namespace :dev do task :build => :environment do User.delete_all - User.create!( :email => 'ihower@rulingcom.com', :password => 'password', :password_confirmation => 'password' ) + User.create!( :email => 'ihower@rulingcom.com', :password => 'password', :password_confirmation => 'password', :use_attributes => ["teacher"] ) + + UserAttribute.create!( :ident => "teacher", :name => "Teacher", :attrs => [ "name" => { :type => 'text_field', :width => 100 }, + "title" => { :type => 'text_field', :width => 100 } ] ) [Announcement, Item, Snippet, Layout].each { |m| m.delete_all } Layout.create!( :name => 'root', :description => 'root', :content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.layout.zh_tw").read,