From 899ac6f654c2ff98532a147cfc6165b12efe1bbb Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 30 Dec 2014 14:29:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=AF=BC=E5=87=BAexcel=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 + Gemfile.lock | 5 ++ app/controllers/bids_controller.rb | 1 + app/controllers/homework_attach_controller.rb | 84 +++++++++++++----- app/views/bids/_homework_list.html.erb | 2 +- .../homework_attach/_homeworks_list.html.erb | 15 ++-- .../get_batch_homeworks.js.erb | 2 +- .../homework_attach/get_homeworks.js.erb | 2 +- .../get_not_batch_homework.js.erb | 2 +- config/initializers/20-mime_types.rb | 1 + config/locales/zh.yml | 12 ++- public/images/icon_excel.gif | Bin 0 -> 1072 bytes public/stylesheets/nyan.css | 8 ++ public/stylesheets/resource.css | 1 + 14 files changed, 103 insertions(+), 34 deletions(-) create mode 100644 public/images/icon_excel.gif diff --git a/Gemfile b/Gemfile index 91e72a745..f462133c3 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,8 @@ gem "coderay", "~> 1.0.6" gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] gem "builder", "3.0.0" gem 'acts-as-taggable-on', '2.4.1' +gem 'spreadsheet' +gem 'ruby-ole' group :development do gem 'better_errors', path: 'lib/better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 6916219a9..771928e40 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -192,6 +192,7 @@ GEM rails (>= 3.2.0) sass-rails rmagick (2.13.2) + ruby-ole (1.2.11.7) ruby-openid (2.1.8) rubyzip (1.1.6) sass (3.3.10) @@ -214,6 +215,8 @@ GEM spork (0.9.2) spork-testunit (0.0.8) spork (>= 0.6.0) + spreadsheet (1.0.0) + ruby-ole (>= 1.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -272,11 +275,13 @@ DEPENDENCIES rails (= 3.2.13) rich (= 1.4.6) rmagick (>= 2.0.0) + ruby-ole ruby-openid (~> 2.1.4) sass-rails (~> 3.2.3) seems_rateable! selenium-webdriver (~> 2.42.0) shoulda (~> 3.5.0) spork-testunit (~> 0.0.8) + spreadsheet therubyracer uglifier (>= 1.0.3) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index e3b8b9a66..ba6ceccc1 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -498,6 +498,7 @@ class BidsController < ApplicationController (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1 WHERE table1.t_score IS NULL") + @not_batch_homework = true @cur_type = 1 else all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index a8e5cf352..fc07bb202 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -21,6 +21,7 @@ class HomeworkAttachController < ApplicationController #获取未批作业列表 def get_not_batch_homework + @not_batch_homework = true sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" get_not_batch_homework_list sort,direction, @bid.id @cur_page = params[:page] || 1 @@ -28,12 +29,17 @@ class HomeworkAttachController < ApplicationController @direction = direction == 'asc'? 'desc' : 'asc' respond_to do |format| format.js + format.xls { + send_data(homework_to_xls(@all_homework_list), :type => "text/excel;charset=utf-8; header=present", + :filename => "not_rated_homework_#{Time.now.strftime("%Y%m%d")}.xls") + } end end #获取已评作业列表 def get_batch_homeworks sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" + @is_batch_homeworks = true if sort == 't_socre' order_by = "t_score #{direction}" elsif sort == 's_socre' @@ -53,33 +59,18 @@ class HomeworkAttachController < ApplicationController @direction = direction == 'asc'? 'desc' : 'asc' respond_to do |format| format.js - format.csv { - send_data(homework_to_csv(all_homework_list), :type => 'text/csv; header=present', :filename => 'issues.csv') + format.xls { + send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present", + :filename => "been_rated_homework_#{Time.now.strftime("%Y%m%d")}.xls") } end end - def homework_to_csv items - encoding = l(:general_csv_encoding) - columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"] - export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| - # csv header fields - csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) } - # csv lines - items.each do |homework| - csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding), - Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding), - Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding), - Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)] - end - end - export - end - #获取所有作业列表 def get_homeworks + @is_all_homeworks = true sort, direction = params[:sort] || "s_socre", params[:direction] || "desc" if sort == 't_socre' order_by = "t_score #{direction}" @@ -99,6 +90,10 @@ class HomeworkAttachController < ApplicationController @direction = direction == 'asc'? 'desc' : 'asc' respond_to do |format| format.js + format.xls { + send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present", + :filename => "all_homework_#{Time.now.strftime("%Y%m%d")}.xls") + } end end @@ -582,18 +577,65 @@ class HomeworkAttachController < ApplicationController elsif sort == 'time' order_by = "created_at #{direction}" end - all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, + @all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score FROM homework_attaches WHERE bid_id = #{bid_id} ORDER BY #{order_by}) AS table1 WHERE table1.t_score IS NULL") - @homework_list = paginateHelper all_homework_list,10 + @homework_list = paginateHelper @all_homework_list,10 end #获取指定作业的所有成员 def users_for_homework homework homework.nil? ? [] : (homework.users + [homework.user]) end + + def homework_to_csv items + encoding = l(:general_csv_encoding) + columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"] + + + export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| + # csv header fields + csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) } + # csv lines + items.each do |homework| + csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding), + Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding), + Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding), + Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)] + end + end + export + end + + def homework_to_xls items + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "homework" + + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name), + l(:excel_t_score),l(:excel_n_score),l(:excel_commit_time)]) + count_row = 1 + items.each do |homework| + sheet1[count_row,0]=homework.user.id + sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s + sheet1[count_row,2] = homework.user.login + sheet1[count_row,3] = homework.user.user_extensions.student_id + sheet1[count_row,4] = homework.user.mail + sheet1[count_row,5] = homework.name + sheet1[count_row,6] =(homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score) + sheet1[count_row,7] = homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score) + sheet1[count_row,8] = format_time(homework.created_at) + count_row += 1 + end + + book.write xls_report + xls_report.string + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 202a2ee91..6572ee2c9 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -59,7 +59,7 @@ :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :remote => false, - :is_student_batch_homework => @is_student_batch_homework}%> + :not_batch_homework => @not_batch_homework,:is_student_batch_homework => @is_student_batch_homework}%> diff --git a/app/views/homework_attach/_homeworks_list.html.erb b/app/views/homework_attach/_homeworks_list.html.erb index 6ada00bb9..9c960d8b8 100644 --- a/app/views/homework_attach/_homeworks_list.html.erb +++ b/app/views/homework_attach/_homeworks_list.html.erb @@ -1,7 +1,9 @@ <% is_teacher = is_course_teacher(User.current,@bid.courses.first) %> <% is_my_homework ||= false %> <% is_student_batch_homework ||= false %> - +<% is_batch_homeworks ||= false %> +<% not_batch_homework ||= false %> +<% is_all_homeworks ||= false %> <% unless is_my_homework || is_student_batch_homework %>
@@ -9,7 +11,10 @@ ( <%= homework_count%> ) - + <%= link_to l(:label_export_excel), get_batch_homeworks_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if is_batch_homeworks%> + <%= link_to l(:label_export_excel), get_not_batch_homework_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if not_batch_homework%> + <%= link_to l(:label_export_excel), get_homeworks_homework_attach_index_path(:bid_id => @bid.id,:format => 'xls'),:class=>'xls' if is_all_homeworks%> + 按  <%= link_to l(:label_anonymous_comments), sort_homework_path(@bid, 's_socre', @direction), {:remote => true}%> @@ -63,10 +68,4 @@ <%= anonymous_comment_notice(@bid, @bid.courses.first) %> - <% other_formats_links do |f| %> - <%= f.link_to 'CSV', :url => params %> - <% end %> - <% end %> diff --git a/app/views/homework_attach/get_batch_homeworks.js.erb b/app/views/homework_attach/get_batch_homeworks.js.erb index 8ca588aab..249e52164 100644 --- a/app/views/homework_attach/get_batch_homeworks.js.erb +++ b/app/views/homework_attach/get_batch_homeworks.js.erb @@ -1,4 +1,4 @@ $('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', - :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>'); + :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true,:is_batch_homeworks => @is_batch_homeworks} )) %>'); for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");} $("#tb_2").removeClass().addClass("hovertab"); \ No newline at end of file diff --git a/app/views/homework_attach/get_homeworks.js.erb b/app/views/homework_attach/get_homeworks.js.erb index 9293af807..06a22924a 100644 --- a/app/views/homework_attach/get_homeworks.js.erb +++ b/app/views/homework_attach/get_homeworks.js.erb @@ -1,5 +1,5 @@ $('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', - :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>'); + :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true,:is_all_homeworks => @is_all_homeworks} )) %>'); for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");} $("#tb_3").removeClass().addClass("hovertab"); diff --git a/app/views/homework_attach/get_not_batch_homework.js.erb b/app/views/homework_attach/get_not_batch_homework.js.erb index 1f8214821..314853d13 100644 --- a/app/views/homework_attach/get_not_batch_homework.js.erb +++ b/app/views/homework_attach/get_not_batch_homework.js.erb @@ -1,4 +1,4 @@ $('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', - :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>'); + :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true,:not_batch_homework => @not_batch_homework} )) %>'); for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");} $("#tb_1").removeClass().addClass("hovertab"); \ No newline at end of file diff --git a/config/initializers/20-mime_types.rb b/config/initializers/20-mime_types.rb index cfd35a3e9..d84c2472d 100644 --- a/config/initializers/20-mime_types.rb +++ b/config/initializers/20-mime_types.rb @@ -1,4 +1,5 @@ # Add new mime types for use in respond_to blocks: Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV) +Mime::Type.register "text/excel", :xls diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 0ff27dad2..0620a8355 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2090,7 +2090,17 @@ zh: label_contest_delete: 删除竞赛 label_noawards_current: 暂未评奖 - + excel_user_id: 学生id + excel_user_name: 用户名 + excel_nickname: 昵称 + excel_student_id: 学号 + excel_mail: 电子邮箱 + excel_homework_name: 作品名 + excel_t_score: 教师评分 + excel_n_score: 匿名评分 + excel_commit_time: 提交时间 + label_export_excel: 导出Excel + label_softapplication: 应用软件 label_attending_contest: 参加竞赛 label_new_attendingcontest_work: 新建参赛作品 diff --git a/public/images/icon_excel.gif b/public/images/icon_excel.gif new file mode 100644 index 0000000000000000000000000000000000000000..d2e309ef5f53b6ef16f08ce68b61038dd37271e9 GIT binary patch literal 1072 zcmZ?wbhEHb6k`xz_|5#E|g^>lwmEFV<(yGD3$LdQ|KaF;3`)HL~ioM?(#)$3MKCHg|702 zZVE;2iX|ROrJhE0VaE00CLk1H+7MyU6m8WUYuy4wadxc<_H79cZHZ1D$u6BK?%nBL zy;)v8nf?>=f+rP*OfE{B-ZtawY_0yU*%xK;) zqjl4)j;(WhwlC=2v2ea~8MeE@>+UIi|OA^@O^0Q|i`EZrU)tZS$=5&9j#r+r04{ z(4s?I&L7x*>F~}=NA_Ji`RMKQ>_yFOTV`!Kx9{E8k8i(xs9imQAylDh-Q?%*U%mhO zQ6|HtcGs%z_U>+GroO(STDMd1a`2^=l^3T|$C+Nj_d&t*BGctZbNhLt)j5hsgM zRb<(Ji%1%~cFi+pJYnNm;=x1yBEV?|KH!C3+vr`B94@f6hxVVT~-yMeWBl7>=Fz|1Qrr>xkX&#q@EbRd9- zU-`!mMa4|v2ge&{J}^A2#N1&jJHh7AmogE}6HE&gP8B6{Ok{DYOL1cDnyl`f_mD3o zfQ5OntFRi6MaZk*rEW=8GC7l$sGbg97{+B$V8GwY)*w>)@sX;4szLK1i3x=Q-Tjsp XxA Date: Tue, 30 Dec 2014 14:33:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=8A=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E5=AD=A6=E7=94=9F=E4=BF=A1=E6=81=AF=E3=80=8Bbug=20Sig?= =?UTF-8?q?ned-off-by:=20alan=20<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1230062844_create_pro_for_search_member.rb | 110 ++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20141230062844_create_pro_for_search_member.rb diff --git a/db/migrate/20141230062844_create_pro_for_search_member.rb b/db/migrate/20141230062844_create_pro_for_search_member.rb new file mode 100644 index 000000000..403e9d05f --- /dev/null +++ b/db/migrate/20141230062844_create_pro_for_search_member.rb @@ -0,0 +1,110 @@ +class CreateProForSearchMember < ActiveRecord::Migration + def up + sql_delete = ("DROP PROCEDURE IF EXISTS `member_score`;") + sql = (" + CREATE PROCEDURE `member_score`(IN courseid INT, IN groupid INT,IN start_from INT, IN nums INT, IN sort_by VARCHAR(10)) +BEGIN + + + + CREATE TEMPORARY TABLE IF NOT EXISTS mems ( + id INT , + user_id INT, + course_id INT, + created_on DATETIME, + course_group_id INT, + score FLOAT DEFAULT 0 + ); + TRUNCATE TABLE mems; + + CREATE TEMPORARY TABLE IF NOT EXISTS mem_home ( + id INT, + user_id INT, + course_id INT, + created_on DATETIME, + course_group_id INT, + home_id INT, + score FLOAT DEFAULT 0 + ); + TRUNCATE TABLE mem_home; + + CREATE TEMPORARY TABLE IF NOT EXISTS t_scores ( + + home_id INT, + score FLOAT + ); + TRUNCATE TABLE t_scores; + + CREATE TEMPORARY TABLE IF NOT EXISTS s_scores ( + + home_id INT, + score FLOAT + ); + TRUNCATE TABLE s_scores; + + CREATE TEMPORARY TABLE IF NOT EXISTS scores ( + + user_id INT, + score FLOAT + ); + TRUNCATE TABLE scores; + + + + INSERT INTO mems (id, user_id, course_id, created_on, course_group_id) + (SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id + FROM members,students_for_courses WHERE members.course_id = courseid + AND members.course_id = students_for_courses.course_id AND members.user_id =students_for_courses.student_id); + + INSERT INTO mem_home (id, user_id, course_id, created_on, course_group_id,home_id) + (SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id, homework_attaches.id + FROM members, homework_attaches WHERE course_id = courseid + AND members.user_id = homework_attaches.user_id AND members.user_id IN (SELECT student_id FROM students_for_courses WHERE course_id = courseid) + AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = courseid )); + + INSERT INTO t_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars) + FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home) + AND is_teacher_score = 1 + GROUP BY rateable_id); + + INSERT INTO s_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars) + FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home) + AND is_teacher_score = 0 + GROUP BY rateable_id) ; + + UPDATE mem_home, t_scores SET mem_home.score = t_scores.score WHERE mem_home.home_id = t_scores.home_id ; + + UPDATE mem_home, s_scores SET mem_home.score = s_scores.score WHERE mem_home.home_id = s_scores.home_id AND mem_home.score = 0; + + INSERT INTO scores (user_id, score) (SELECT user_id, SUM(score) FROM mem_home GROUP BY user_id); + UPDATE mems, scores SET mems.score = scores.score WHERE mems.user_id = scores.user_id; + IF sort_by = '' OR sort_by = 'desc' THEN + IF groupid <> 0 THEN + SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score DESC; + ELSE + IF nums <> 0 THEN + SELECT * FROM mems ORDER BY score DESC LIMIT start_from, nums; + ELSE + SELECT * FROM mems ORDER BY score DESC; + end IF; + END if; + ELSE + IF groupid <> 0 THEN + SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score ASC ; + ELSE + IF nums <> 0 THEN + SELECT * FROM mems ORDER BY score ASC LIMIT start_from, nums; + ELSE + SELECT * FROM mems ORDER BY score ASC; + end IF; + END IF; + END IF; + END; +") + execute(sql_delete) + execute(sql) + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 6ab3c5657..eb84e19e6 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 => 20141230034253) do +ActiveRecord::Schema.define(:version => 20141230062844) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false