From ee9d82bfc7304f1b6d5b6263e8dbd0646804cad9 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 8 Jan 2015 17:42:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=AE=9E=E7=8E=B0=E6=96=87=E4=BB=B6=E8=B0=83?= =?UTF-8?q?=E6=9F=A5=E7=9A=84model=E3=80=81control=E3=80=81view=E7=9A=84?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=202.=E4=BF=AE=E6=AD=A3=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A1=A8=E4=B9=8B=E9=97=B4=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=203.=E4=BF=AE=E6=AD=A3=E4=BB=A3=E7=A0=81=E4=B8=AD?= =?UTF-8?q?=E5=8D=95=E5=A4=8D=E6=95=B0=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_answer_controller.rb | 2 ++ app/controllers/poll_answers_controller.rb | 0 app/controllers/poll_controller.rb | 2 ++ app/controllers/poll_question_controller.rb | 2 ++ app/controllers/poll_user_controller.rb | 2 ++ app/controllers/poll_vote_controller.rb | 2 ++ app/controllers/poll_votes_controller.rb | 0 app/controllers/polls_questions_controller.rb | 0 app/models/poll.rb | 9 +++++++++ app/models/poll_answer.rb | 7 +++++++ app/models/poll_answers.rb | 5 ----- app/models/poll_question.rb | 8 ++++++++ app/models/poll_questions.rb | 5 ----- app/models/poll_user.rb | 5 +++-- app/models/poll_vote.rb | 8 ++++++++ app/models/poll_votes.rb | 7 ------- app/models/polls.rb | 5 ----- app/models/user.rb | 7 +++++++ db/migrate/20150108034148_create_polls.rb | 6 +++++- .../20150108034253_create_poll_questions.rb | 8 ++++++-- db/migrate/20150108034414_create_poll_answers.rb | 8 ++++++-- db/migrate/20150108035301_create_poll_votes.rb | 10 +++++++--- db/migrate/20150108035338_create_poll_users.rb | 6 +++++- db/schema.rb | 16 ++++++++-------- 24 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 app/controllers/poll_answer_controller.rb delete mode 100644 app/controllers/poll_answers_controller.rb create mode 100644 app/controllers/poll_question_controller.rb create mode 100644 app/controllers/poll_vote_controller.rb delete mode 100644 app/controllers/poll_votes_controller.rb delete mode 100644 app/controllers/polls_questions_controller.rb create mode 100644 app/models/poll.rb create mode 100644 app/models/poll_answer.rb delete mode 100644 app/models/poll_answers.rb create mode 100644 app/models/poll_question.rb delete mode 100644 app/models/poll_questions.rb create mode 100644 app/models/poll_vote.rb delete mode 100644 app/models/poll_votes.rb delete mode 100644 app/models/polls.rb diff --git a/app/controllers/poll_answer_controller.rb b/app/controllers/poll_answer_controller.rb new file mode 100644 index 000000000..521f7ed3f --- /dev/null +++ b/app/controllers/poll_answer_controller.rb @@ -0,0 +1,2 @@ +class PollAnswerController < ApplicationController +end \ No newline at end of file diff --git a/app/controllers/poll_answers_controller.rb b/app/controllers/poll_answers_controller.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index e69de29bb..a21fdb549 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -0,0 +1,2 @@ +class PollController < ApplicationController +end \ No newline at end of file diff --git a/app/controllers/poll_question_controller.rb b/app/controllers/poll_question_controller.rb new file mode 100644 index 000000000..46a75c0ab --- /dev/null +++ b/app/controllers/poll_question_controller.rb @@ -0,0 +1,2 @@ +class PollQuestionController < ApplicationController +end \ No newline at end of file diff --git a/app/controllers/poll_user_controller.rb b/app/controllers/poll_user_controller.rb index e69de29bb..0373fe085 100644 --- a/app/controllers/poll_user_controller.rb +++ b/app/controllers/poll_user_controller.rb @@ -0,0 +1,2 @@ +class PollUserController < ApplicationController +end \ No newline at end of file diff --git a/app/controllers/poll_vote_controller.rb b/app/controllers/poll_vote_controller.rb new file mode 100644 index 000000000..e77bdc622 --- /dev/null +++ b/app/controllers/poll_vote_controller.rb @@ -0,0 +1,2 @@ +class PollVoteController < ApplicationController +end \ No newline at end of file diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/controllers/polls_questions_controller.rb b/app/controllers/polls_questions_controller.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/models/poll.rb b/app/models/poll.rb new file mode 100644 index 000000000..803ee6ac6 --- /dev/null +++ b/app/models/poll.rb @@ -0,0 +1,9 @@ +class Poll < ActiveRecord::Base + #attr_accessible :closed_at, :polls_group_id, :polls_name, :polls_status, :polls_type, :published_at, :user_id + include Redmine::SafeAttributes + + belongs_to :user + has_many :poll_questions, :dependent => :destroy + has_many :poll_users, :dependent => :destroy + has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 +end diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb new file mode 100644 index 000000000..93c75da97 --- /dev/null +++ b/app/models/poll_answer.rb @@ -0,0 +1,7 @@ +class PollAnswer < ActiveRecord::Base + # attr_accessible :answer_position, :answer_text, :poll_questions_id + include Redmine::SafeAttributes + + belongs_to :poll_question + has_many :poll_votes, :dependent => :destroy +end diff --git a/app/models/poll_answers.rb b/app/models/poll_answers.rb deleted file mode 100644 index 8a8c3169a..000000000 --- a/app/models/poll_answers.rb +++ /dev/null @@ -1,5 +0,0 @@ -class PollAnswers < ActiveRecord::Base - attr_accessible :answer_position, :answer_text, :poll_questions_id - - belongs_to :poll_questions -end diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb new file mode 100644 index 000000000..66dcea67e --- /dev/null +++ b/app/models/poll_question.rb @@ -0,0 +1,8 @@ +class PollQuestion < ActiveRecord::Base + # attr_accessible :is_necessary, :polls_id, :question_title, :question_type + include Redmine::SafeAttributes + + belongs_to :poll + has_many :poll_answers, :dependent => :destroy + has_many :poll_votes, :dependent => :destroy +end diff --git a/app/models/poll_questions.rb b/app/models/poll_questions.rb deleted file mode 100644 index ce272a218..000000000 --- a/app/models/poll_questions.rb +++ /dev/null @@ -1,5 +0,0 @@ -class PollQuestions < ActiveRecord::Base - attr_accessible :is_necessary, :polls_id, :question_title, :question_type - - belongs_to :polls -end diff --git a/app/models/poll_user.rb b/app/models/poll_user.rb index a03f6b17d..e7a122da9 100644 --- a/app/models/poll_user.rb +++ b/app/models/poll_user.rb @@ -1,6 +1,7 @@ class PollUser < ActiveRecord::Base - attr_accessible :poll_id, :user_id + # attr_accessible :poll_id, :user_id + include Redmine::SafeAttributes - belongs_to :polls + belongs_to :poll belongs_to :user end diff --git a/app/models/poll_vote.rb b/app/models/poll_vote.rb new file mode 100644 index 000000000..550563e38 --- /dev/null +++ b/app/models/poll_vote.rb @@ -0,0 +1,8 @@ +class PollVote < ActiveRecord::Base + # attr_accessible :poll_answers_id, :poll_questions_id, :user_id, :vote_text + include Redmine::SafeAttributes + + belongs_to :poll_answer + belongs_to :poll_question + belongs_to :user +end diff --git a/app/models/poll_votes.rb b/app/models/poll_votes.rb deleted file mode 100644 index fe52b4ac5..000000000 --- a/app/models/poll_votes.rb +++ /dev/null @@ -1,7 +0,0 @@ -class PollVotes < ActiveRecord::Base - attr_accessible :poll_answers_id, :poll_questions_id, :user_id, :vote_text - - belongs_to :poll_answers - belongs_to :poll_questions - belongs_to :user -end diff --git a/app/models/polls.rb b/app/models/polls.rb deleted file mode 100644 index 02de95dce..000000000 --- a/app/models/polls.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Polls < ActiveRecord::Base - attr_accessible :closed_at, :polls_group_id, :polls_name, :polls_status, :polls_type, :published_at, :user_id - - belongs_to :user -end diff --git a/app/models/user.rb b/app/models/user.rb index e966742f1..735b80762 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -77,6 +77,13 @@ class User < Principal has_many :homework_attaches, :through => :homework_users has_many :homework_evaluations + #问卷相关关关系 + has_many :poll_users, :dependent => :destroy + has_many :poll_votes, :dependent => :destroy + has_many :poll, :dependent => :destroy #用户创建的问卷 + has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷 + # end + has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} has_many :changesets, :dependent => :nullify diff --git a/db/migrate/20150108034148_create_polls.rb b/db/migrate/20150108034148_create_polls.rb index e074e08be..454f73b21 100644 --- a/db/migrate/20150108034148_create_polls.rb +++ b/db/migrate/20150108034148_create_polls.rb @@ -1,5 +1,5 @@ class CreatePolls < ActiveRecord::Migration - def change + def up create_table :polls do |t| t.string :polls_name t.string :polls_type @@ -12,4 +12,8 @@ class CreatePolls < ActiveRecord::Migration t.timestamps end end + + def down + drop_table :polls + end end diff --git a/db/migrate/20150108034253_create_poll_questions.rb b/db/migrate/20150108034253_create_poll_questions.rb index 8e795deda..2fa586dd5 100644 --- a/db/migrate/20150108034253_create_poll_questions.rb +++ b/db/migrate/20150108034253_create_poll_questions.rb @@ -1,12 +1,16 @@ class CreatePollQuestions < ActiveRecord::Migration - def change + def up create_table :poll_questions do |t| t.string :question_title t.integer :question_type t.integer :is_necessary - t.integer :polls_id + t.integer :poll_id t.timestamps end end + + def down + drop_table :poll_questions + end end diff --git a/db/migrate/20150108034414_create_poll_answers.rb b/db/migrate/20150108034414_create_poll_answers.rb index bc9ac6d9f..b6276fad0 100644 --- a/db/migrate/20150108034414_create_poll_answers.rb +++ b/db/migrate/20150108034414_create_poll_answers.rb @@ -1,11 +1,15 @@ class CreatePollAnswers < ActiveRecord::Migration - def change + def up create_table :poll_answers do |t| - t.integer :poll_questions_id + t.integer :poll_question_id t.text :answer_text t.integer :answer_position t.timestamps end end + + def down + drop_table :poll_answers + end end diff --git a/db/migrate/20150108035301_create_poll_votes.rb b/db/migrate/20150108035301_create_poll_votes.rb index e22228dc2..0b7192ab8 100644 --- a/db/migrate/20150108035301_create_poll_votes.rb +++ b/db/migrate/20150108035301_create_poll_votes.rb @@ -1,12 +1,16 @@ class CreatePollVotes < ActiveRecord::Migration - def change + def up create_table :poll_votes do |t| t.integer :user_id - t.integer :poll_questions_id - t.integer :poll_answers_id + t.integer :poll_question_id + t.integer :poll_answer_id t.text :vote_text t.timestamps end end + + def down + drop_table :poll_votes + end end diff --git a/db/migrate/20150108035338_create_poll_users.rb b/db/migrate/20150108035338_create_poll_users.rb index 158937ce0..73d155890 100644 --- a/db/migrate/20150108035338_create_poll_users.rb +++ b/db/migrate/20150108035338_create_poll_users.rb @@ -1,5 +1,5 @@ class CreatePollUsers < ActiveRecord::Migration - def change + def up create_table :poll_users do |t| t.integer :user_id t.integer :poll_id @@ -7,4 +7,8 @@ class CreatePollUsers < ActiveRecord::Migration t.timestamps end end + + def down + drop_table :poll_users + end end diff --git a/db/schema.rb b/db/schema.rb index e919d4118..00d308293 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -791,18 +791,18 @@ ActiveRecord::Schema.define(:version => 20150108035338) do end create_table "poll_answers", :force => true do |t| - t.integer "poll_questions_id" + t.integer "poll_question_id" t.text "answer_text" t.integer "answer_position" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "poll_questions", :force => true do |t| t.string "question_title" t.integer "question_type" t.integer "is_necessary" - t.integer "polls_id" + t.integer "poll_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end @@ -816,11 +816,11 @@ ActiveRecord::Schema.define(:version => 20150108035338) do create_table "poll_votes", :force => true do |t| t.integer "user_id" - t.integer "poll_questions_id" - t.integer "poll_answers_id" + t.integer "poll_question_id" + t.integer "poll_answer_id" t.text "vote_text" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "polls", :force => true do |t|