Add UserAttribute model, suppose it will store user model want to use which attribute group

This commit is contained in:
Wen-Tien Chang 2010-03-04 17:11:18 +08:00
parent 13065aa85a
commit 9f1de1b543
5 changed files with 32 additions and 3 deletions

View File

@ -3,4 +3,6 @@ class User
devise :authenticatable, :recoverable, :rememberable, :trackable
key :use_attributes
end

View File

@ -0,0 +1,9 @@
class UserAttribute
include MongoMapper::Document
key :ident, String
key_i18n :name, String
key_i18n :attrs, Array
end

View File

@ -8,6 +8,7 @@
<table>
<tr>
<th>Attrs</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
@ -15,9 +16,13 @@
<% @users.each do |user| %>
<tr>
<td><%= user.use_attributes.join(",") %></td>
<td><%#= user.name %></td>
<td><%= user.email %></td>
<td><%= link_to 'Edit', edit_panel_user_path(user) %> | <%= link_to 'Destroy', panel_user_path(user), :method => :delete %></td>
<td>
<%= link_to 'Show', panel_user_path(user) %>
<%= link_to 'Edit', edit_panel_user_path(user) %> |
<%= link_to 'Destroy', panel_user_path(user), :method => :delete %></td>
</tr>
<% end %>
</table>

View File

@ -0,0 +1,10 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1>Users panel</h1>
<%=h @user.name %>
<%=h @user.email %>

View File

@ -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,