homework_attach增加列project_id及相关数据迁移

编辑作业页面增加选择关联项目,以及数据更新项目的实现
This commit is contained in:
sw 2014-06-17 18:49:21 +08:00
parent ab486aa811
commit 97a4aaf8ab
5 changed files with 36 additions and 13 deletions

View File

@ -177,8 +177,10 @@ class HomeworkAttachController < ApplicationController
if User.current.admin? || User.current.member_of?(course)
name = params[:homework_name]
description = params[:homework_description]
project_id = params[:homework_attach][:project_id]
@homework.name = name
@homework.description = description
@homework.project_id = project_id
if params[:attachments]
@homework.save_attachments(params[:attachments])
end
@ -196,7 +198,7 @@ class HomeworkAttachController < ApplicationController
def destroy
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current == @homework
if User.current.admin? || User.current == @homework.user
if @homework.destroy
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }

View File

@ -54,4 +54,16 @@ module HomeworkAttachHelper
raise RuntimeError, 'unknow type, Please input you type into this helper.'
end
end
def user_projects_option
projects = Project.where("id < 8")
type = []
projects.each do |project|
option = []
option << project.name
option << project.id
type << option
end
type
end
end

View File

@ -42,11 +42,16 @@
<div class="box" id="content1">
<%= form_for(@homework) do |f|%>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong>标 题:</strong>
<strong>标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题:</strong>&nbsp;
<%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%>
</p>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong style="vertical-align: top">描 述:</strong>
<strong>关联项目:</strong>
<%= f.select :project_id, options_for_select(user_projects_option),:name => "project_id", :required => true%>
<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %>
</p>
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
<strong style="vertical-align: top">描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述:</strong>&nbsp;
<span style="margin-left:-10px;padding-right: 20px;">
<%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %>
</span>

View File

@ -0,0 +1,5 @@
class AddProjectIdToHomeworkAttach < ActiveRecord::Migration
def change
add_column :homework_attaches, :project_id, :integer, default: 0
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 => 20140617013146) do
ActiveRecord::Schema.define(:version => 20140617092219) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -348,12 +348,13 @@ ActiveRecord::Schema.define(:version => 20140617013146) do
create_table "homework_attaches", :force => true do |t|
t.integer "bid_id"
t.integer "user_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.string "reward"
t.string "name"
t.string "description"
t.integer "state"
t.integer "project_id", :default => 0
end
create_table "homework_for_courses", :force => true do |t|
@ -960,13 +961,11 @@ ActiveRecord::Schema.define(:version => 20140617013146) do
end
create_table "user_scores", :force => true do |t|
t.integer "user_id", :null => false
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "activity"
end
create_table "user_statuses", :force => true do |t|