From 60b07432926d330981a15a041fbc959807bf032d Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 14 Jan 2015 09:48:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E8=B0=83=E6=9F=A5?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=9C=A8=E7=81=AB=E7=8B=90=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/poll/show.html.erb | 4 ++++ db/schema.rb | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb index 66fcd3bcd..a0c111a79 100644 --- a/app/views/poll/show.html.erb +++ b/app/views/poll/show.html.erb @@ -25,6 +25,7 @@
第1题: 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 *
+
@@ -52,6 +53,7 @@
第2题: 多选题 *
+
@@ -80,6 +82,7 @@
第3题: 单行主观
+
@@ -90,6 +93,7 @@
第4题: 多行主观
+
diff --git a/db/schema.rb b/db/schema.rb index 9c6f4eac3..a58602e37 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 => 20150112024820) do +ActiveRecord::Schema.define(:version => 20150112080435) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -23,6 +23,18 @@ ActiveRecord::Schema.define(:version => 20150112024820) do add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type" add_index "activities", ["user_id"], :name => "index_activities_on_user_id" + create_table "api_keys", :force => true do |t| + t.string "access_token" + t.datetime "expires_at" + t.integer "user_id" + t.boolean "active", :default => true + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token" + add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id" + create_table "applied_projects", :force => true do |t| t.integer "project_id", :null => false t.integer "user_id", :null => false From b6826a74d34cde40c248aa409ea8c6ca6db7ade9 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 14 Jan 2015 11:50:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 4 +- app/models/poll.rb | 2 +- app/models/poll_question.rb | 2 +- app/views/poll/show.html.erb | 181 ++++++++++-------- ...0_add_question_number_to_poll_questions.rb | 9 + db/schema.rb | 7 +- 6 files changed, 115 insertions(+), 90 deletions(-) create mode 100644 db/migrate/20150114022710_add_question_number_to_poll_questions.rb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 9177e044b..88bbfff46 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -19,8 +19,8 @@ class PollController < ApplicationController def show @poll = Poll.find params[:id] - @poll_questions = @poll.poll_questions - + poll_questions = @poll.poll_questions + @poll_questions = paginateHelper poll_questions,3 #分页 respond_to do |format| format.html {render :layout => 'base_courses'} end diff --git a/app/models/poll.rb b/app/models/poll.rb index 803ee6ac6..06f1369c1 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -3,7 +3,7 @@ class Poll < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :user - has_many :poll_questions, :dependent => :destroy + has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number" has_many :poll_users, :dependent => :destroy has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 end diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 66dcea67e..2d9912fc2 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -3,6 +3,6 @@ class PollQuestion < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :poll - has_many :poll_answers, :dependent => :destroy + has_many :poll_answers, :order => "#{PollAnswer.table_name}.answer_position",:dependent => :destroy has_many :poll_votes, :dependent => :destroy end diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb index a0c111a79..26daa8fc5 100644 --- a/app/views/poll/show.html.erb +++ b/app/views/poll/show.html.erb @@ -20,90 +20,105 @@
    - -
  1. -
    - 第1题: 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 * -
    -
    -
    -
- - - - - - - - - - - -
- -
- -
- -
-
- - -
  • -
    - 第2题: 多选题 * -
    -
    -
    - - - - - - - - - - - - -
    - -
    - -
    - -
    -
    -
  • - - -
  • -
    - 第3题: 单行主观 -
    -
    -
    - -
    -
  • - -
  • -
    -
    - 第4题: 多行主观 -
    -
    -
    - -
    -
    -
  • - + <% @poll_questions.each do |pq| %> + <% if pq.question_type == 1 %> + +
  • +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + + + <% pq.poll_answers.each do |pa| %> + + + + <% end %> + +
    + +
    +
    +
  • + <% elsif pq.question_type == 2 %> + +
  • +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + + + <% pq.poll_answers.each do |pa| %> + + + + <% end %> + +
    + +
    +
    +
  • + <% elsif pq.question_type == 3 %> + +
  • +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + +
    +
  • + <% elsif pq.question_type == 4 %> + +
  • +
    +
    + 第<%= pq.question_number %>题: + <%= pq.question_title %> + <% if pq.is_necessary == 1 %> + * + <% end %> +
    +
    +
    + +
    +
    +
  • + <% else %> + + <% end %> + <% end %> - -
    - 下一页 + +
    +
    diff --git a/db/migrate/20150114022710_add_question_number_to_poll_questions.rb b/db/migrate/20150114022710_add_question_number_to_poll_questions.rb new file mode 100644 index 000000000..71f0328be --- /dev/null +++ b/db/migrate/20150114022710_add_question_number_to_poll_questions.rb @@ -0,0 +1,9 @@ +class AddQuestionNumberToPollQuestions < ActiveRecord::Migration + def self.up + add_column :poll_questions, :question_number, :integer + end + + def self.down + remove_column :poll_questions, :question_number + end +end diff --git a/db/schema.rb b/db/schema.rb index a58602e37..53d57d748 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 => 20150112080435) do +ActiveRecord::Schema.define(:version => 20150114022710) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -815,8 +815,9 @@ ActiveRecord::Schema.define(:version => 20150112080435) do t.integer "question_type" t.integer "is_necessary" t.integer "poll_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "question_number" end create_table "poll_users", :force => true do |t|