1.实现文件调查的model、control、view的架构

2.修正完善新增表之间的关系
3.修正代码中单复数不正确的问题
This commit is contained in:
sw 2015-01-08 17:42:46 +08:00
parent 4c6ade4c08
commit ee9d82bfc7
24 changed files with 89 additions and 41 deletions

View File

@ -0,0 +1,2 @@
class PollAnswerController < ApplicationController
end

View File

@ -0,0 +1,2 @@
class PollController < ApplicationController
end

View File

@ -0,0 +1,2 @@
class PollQuestionController < ApplicationController
end

View File

@ -0,0 +1,2 @@
class PollUserController < ApplicationController
end

View File

@ -0,0 +1,2 @@
class PollVoteController < ApplicationController
end

9
app/models/poll.rb Normal file
View File

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

View File

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

View File

@ -1,5 +0,0 @@
class PollAnswers < ActiveRecord::Base
attr_accessible :answer_position, :answer_text, :poll_questions_id
belongs_to :poll_questions
end

View File

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

View File

@ -1,5 +0,0 @@
class PollQuestions < ActiveRecord::Base
attr_accessible :is_necessary, :polls_id, :question_title, :question_type
belongs_to :polls
end

View File

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

8
app/models/poll_vote.rb Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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