add rough user attributes API
This commit is contained in:
		
							parent
							
								
									29ee4585b2
								
							
						
					
					
						commit
						a40b117fbe
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  | @ -2,7 +2,7 @@ class UserAttribute | |||
|    | ||||
|   include MongoMapper::Document | ||||
|    | ||||
|   key :ident, String | ||||
|   key :key, String | ||||
|   key_i18n :name, String | ||||
|   key_i18n :attrs, Array | ||||
|    | ||||
|  |  | |||
|  | @ -1,7 +1,13 @@ | |||
| <% @user_attributes.each do |ua| %> | ||||
|     <h3><%= ua.name %></h3> | ||||
|      | ||||
|     <% ua.attrs.each do |attr|  %> | ||||
|     <p> | ||||
|     <%= label_tag :name %> | ||||
|     <%= text_field_tag "user[name]" %> | ||||
|         <%= f.label attr["name"] %> | ||||
|         <%= f.send(attr["type"], "#{ua.key}_#{attr["key"]}" )%> | ||||
|     </p> | ||||
|     <% end -%> | ||||
| <% end -%> | ||||
| 
 | ||||
| <p> | ||||
|     <%= f.label :email %> | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ | |||
| <% @users.each do |user| %> | ||||
| <tr> | ||||
|     <td><%= user.use_attributes.join(",") %></td> | ||||
|     <td><%#= user.name %></td> | ||||
|     <td><%= user.name %></td> | ||||
|     <td><%= user.email %></td> | ||||
|     <td> | ||||
|         <%= link_to 'Show', panel_user_path(user) %> | ||||
|  |  | |||
|  | @ -2,10 +2,13 @@ namespace :dev do | |||
|    | ||||
|   task :build => :environment do | ||||
|     User.delete_all | ||||
|     UserAttribute.delete_all | ||||
|      | ||||
|     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 } ] ) | ||||
|     UserAttribute.create!( :key => "teacher", :name => "Teacher", :attrs => [ { :name => "Name", :key => "name", :type => "text_field" }, { :name => "Title", :key => "title", :type => 'text_field' } ] ) | ||||
| 
 | ||||
|     UserAttribute.create!( :key => "staff", :name => "Staff", :attrs => [ { :name => "Name", :key => "name", :type => "text_field" }, { :name => "Duty", :key => "duty", :type => 'text_field' } ] ) | ||||
|          | ||||
|     [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, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue