From 7850a2e6f0f954be9df9d68efecbff7e6a31abed Mon Sep 17 00:00:00 2001 From: william Date: Wed, 14 Aug 2013 21:37:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9user=5Fextension?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/my_controller.rb | 2 ++ app/controllers/users_controller.rb | 11 +++++++++++ app/models/user_extension.rb | 11 ----------- app/models/user_extensions.rb | 19 +++++++++++++++++++ app/views/layouts/base_users.html.erb | 8 ++++---- app/views/my/account.html.erb | 4 ++++ app/views/tags/_show_projects.html.erb | 2 +- app/views/tags/_tag.html.erb | 6 ++---- config/settings.yml | 6 ++++++ .../20130814084938_create_user_extensions.rb | 19 +++++++++++++++++++ db/schema.rb | 15 ++++++++++++++- 11 files changed, 82 insertions(+), 21 deletions(-) delete mode 100644 app/models/user_extension.rb create mode 100644 app/models/user_extensions.rb create mode 100644 db/migrate/20130814084938_create_user_extensions.rb diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 2720e11f9..03367073e 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -60,7 +60,9 @@ class MyController < ApplicationController @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) set_language_if_valid @user.language + @user.update_user_extensions() flash[:notice] = l(:notice_account_updated) + redirect_to my_account_path return end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6126e0356..f45a05612 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -434,7 +434,18 @@ class UsersController < ApplicationController def user_fanslist end + + #william + def update_extensions(user_extensions) + user_extensions = params[:user_extensions] + unless user_extensions.nil? + user_extensions = UserExtensions.find_by_id(user_extensions.user_id) + + # user_extensions. + end + end + private def find_user diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb deleted file mode 100644 index cdfad28c6..000000000 --- a/app/models/user_extension.rb +++ /dev/null @@ -1,11 +0,0 @@ -class UserExtension < ActiveRecord::Base - attr_accessible :birthday, :brief_introduction, :fans_num, :finish_project_num, :follow_num, :gender, :good_num, :location, :occupation, :publish_requirement_num, :user_id, :work_experience, :zip_code - - belongs_to :user - validate :validate_user - - def validate_user - errors.add :user_id, :invalid if user.nil? || !user.active? || User.current != user_id - end - -end diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb new file mode 100644 index 000000000..f70cddad8 --- /dev/null +++ b/app/models/user_extensions.rb @@ -0,0 +1,19 @@ +class UserExtensions < ActiveRecord::Base + attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code + #this method was used to update the table user_extensions + def update_user_extensions(birthday=nil,brief_introduction=nil, + gender=nil,location=nil,occupation=nil,work_experience=nil,zip_code=nil) + self.birthday = birthday + self.brief_introduction = brief_introduction + self.gender = gender + self.location = location + self.occupation = occupation + self.work_experience = work_experience + self.zip_code = zip_code + self.save + end + + def get_brief_introduction + return self.brief_introduction + end +end diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index c8367477f..c99f918a1 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -72,14 +72,14 @@
-
+ -
+
<%= render :partial => 'tags/tag', :locals => {:obj => @user,:object_flag => "1"}%>
-
-
+ +
diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 692892537..d9e9a01cc 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -33,6 +33,10 @@

<%= f.text_field :lastname, :required => true %>

+ +

+ <%= f.text_field :brief_introduction, :required => true %> +

<%= f.text_field :mail, :required => true %>

diff --git a/app/views/tags/_show_projects.html.erb b/app/views/tags/_show_projects.html.erb index 9368d1c6d..b4eb6f0a4 100644 --- a/app/views/tags/_show_projects.html.erb +++ b/app/views/tags/_show_projects.html.erb @@ -1,7 +1,7 @@
<% if projects_results.size > 0 %>
-

Projects:

+Projects: <% projects_results.each do |prj| %>

<%= l(:label_tags_project_name) %><%= link_to "#{prj.name}",:controller => "projects",:action => "show",:id => prj.id %>

diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 22bab5e31..8c2c3d90a 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -16,7 +16,7 @@ <%= form_for "tag_for_save",:remote=>true,:url=>tag_path, :update => "tags_show", :complete => '$("#put-tag-form-issue").hide();' do |f| %> - <%= f.text_field :name ,:id => "name-issue",:size=>"30",:require=>true %> + <%= f.text_field :name ,:id => "name-issue",:size=>"30",:require=>true,:maxlength => 25,:minlength=>1 %> <%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%> <%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%> <%= f.submit "add"%> @@ -34,8 +34,6 @@ <%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form', {:focus => 'name'} %> <% end %> - -
<%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
@@ -43,7 +41,7 @@ <%= form_for "tag_for_save",:remote=>true,:url=>tag_path, :update => "tags_show", :complete => '$("#put-tag-form").hide();' do |f| %> - <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true%> + <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => 25,:minlength=>1 %> <%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%> <%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%> <%= f.submit "add"%> diff --git a/config/settings.yml b/config/settings.yml index 384e7d07b..ca2f5416a 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -236,3 +236,9 @@ non_working_week_days: show_tags_length: format: int default: 5 +tags_min_length: + format: int + default: 1 +tags_max_length: + format: int + default: 25 diff --git a/db/migrate/20130814084938_create_user_extensions.rb b/db/migrate/20130814084938_create_user_extensions.rb new file mode 100644 index 000000000..f160bd52c --- /dev/null +++ b/db/migrate/20130814084938_create_user_extensions.rb @@ -0,0 +1,19 @@ +class CreateUserExtensions < ActiveRecord::Migration + def self.up + create_table :user_extensions do |t| + t.column :user_id,:integer,:null => false + t.column :birthday,:date + t.column :brief_introduction,:string + t.column :gender,:integer + t.column :location,:string + t.column :occupation,:string + t.column :work_experience,:integer + t.column :zip_code,:integer + t.timestamps + end + end + + def self.down + drop_table :user_extensions + end +end diff --git a/db/schema.rb b/db/schema.rb index c5d03c06c..fd0a86fe2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130811122119) do +ActiveRecord::Schema.define(:version => 20130814084938) do create_table "a_user_watchers", :force => true do |t| t.string "name" @@ -625,6 +625,19 @@ ActiveRecord::Schema.define(:version => 20130811122119) do t.integer "fields_bits", :default => 0 end + create_table "user_extensions", :force => true do |t| + t.integer "user_id", :null => false + t.date "birthday" + t.string "brief_introduction" + t.integer "gender" + t.string "location" + t.string "occupation" + t.integer "work_experience" + t.integer "zip_code" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "user_preferences", :force => true do |t| t.integer "user_id", :default => 0, :null => false t.text "others"