问卷显示

This commit is contained in:
z9hang 2015-01-14 11:50:59 +08:00
parent 60b0743292
commit b6826a74d3
6 changed files with 115 additions and 90 deletions

View File

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

View File

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

View File

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

View File

@ -20,78 +20,88 @@
<div class="ur_card">
<ol class="ur_questions">
<% @poll_questions.each do |pq| %>
<% if pq.question_type == 1 %>
<!-- 单选题 -->
<li class="ur_question_item radio">
<div class="ur_title">
<span class="title_index">第1题</span> 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 <span class="ur_required" title="必答">*</span>
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
</td>
</tr>
<tr >
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
</td>
</tr>
<tr>
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
<label >
<input class="ur_radio" type="radio" value="新建选项" >
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</li><!--单选题 end-->
</li>
<% elsif pq.question_type == 2 %>
<!-- 多选题 -->
<li class="ur_question_item checkbox">
<div class="ur_title">
<span class="title_index">第2题</span> 多选题 <span class="ur_required" title="必答">*</span>
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table">
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label ><input class="ur_checkbox" type="checkbox" value="新建选项" > 新建选项 </label>
</td>
</tr>
<tr class="ur_tr_even">
<td>
<label ><input class="ur_checkbox" type="checkbox" value="新建选项" > 新建选项 </label>
</td>
</tr>
<tr>
<td>
<label ><input class="ur_checkbox" type="checkbox" value="新建选项" > 新建选项 </label>
<label >
<input class="ur_checkbox" type="checkbox" value="新建选项" >
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</li><!--多选题 end-->
</li>
<% elsif pq.question_type == 3 %>
<!-- 单行文字-->
<li class="ur_question_item text">
<div class="ur_title">
<span class="title_index">第3题</span> 单行主观
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<input class="ur_text ur_textbox" type="text" size="" maxlength=""value="">
</div>
</li><!--当行输入 end-->
<% elsif pq.question_type == 4 %>
<!-- 多行文字-->
<li class="ur_question_item textarea">
<div class="ur_preview">
<div class="ur_title">
<span class="title_index">第4题</span> 多行主观
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
@ -99,11 +109,16 @@
</div>
</div>
</li><!--多行输入 end-->
<% else %>
<!-- 未知题型 -->
<% end %>
<% end %>
</ol>
<div class="ur_buttons">
<a href="#" class=" ur_button" >下一页</a>
<ul class="wlist">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>
<div class="cl"></div>
<div class="ur_buttons" style="width: 100px;">
<a href="#" class="ur_button" >提交</a>
</div>
<div class="cl"></div>

View File

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

View File

@ -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
@ -817,6 +817,7 @@ ActiveRecord::Schema.define(:version => 20150112080435) do
t.integer "poll_id"
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|