From c7b19d8f2e21a324ab038467e82c39e0157c020a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 21 May 2014 14:10:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BD=9C=E4=B8=9A=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 53 +++++++++++++++---- app/views/homework_attach/edit.html.erb | 0 app/views/homework_attach/new.html.erb | 33 ++++++++++++ config/locales/zh.yml | 5 ++ config/routes.rb | 2 +- 5 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 app/views/homework_attach/edit.html.erb create mode 100644 app/views/homework_attach/new.html.erb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index ed31f8f7..c3ac1519 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -8,22 +8,50 @@ class HomeworkAttachController < ApplicationController end end - def create - @homework = HomeworkAttach.new(params[:homework]) + def add_users users + if users != nil && users.count > 0 + users.each do |user| + @homework.homework_users.build(:user_id => user.id) + @homework.save + end + end + end - respond_to do |format| - if @homework.save - format.html { redirect_to @homework, notice: 'Post was successfully created.' } - format.json { render json: @homework, status: :created, location: @homework } - else - format.html { render action: "new" } - format.json { render json: @homework.errors, status: :unprocessable_entity } + def create + if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) + user_id = params[:user_id] + bid_id = params[:bid_id] + sta = 0 + name = params[:new_form][:name] + description = params[:new_form][:description] + options = { + :user_id => user_id, + :state => sta, + :name => name, + :description => description, + :bid_id => bid_id + } + + @homework = HomeworkAttach.new(options) + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + @homework.save + respond_to do |format| + if @homework.save + format.html { redirect_to @homework, notice: 'Post was successfully created.' } + format.json { render json: @homework, status: :created, location: @homework } + else + format.html { render action: "new" } + format.json { render json: @homework.errors, status: :unprocessable_entity } + end end end end def new @homework = HomeworkAttach.new + @bid = Bid.find(params[:id]) respond_to do |format| format.html # new.html.erb @@ -49,7 +77,12 @@ class HomeworkAttachController < ApplicationController end def destroy - + @homework = HomeworkAttach.find(params([:id])) + @homework.destroy + respond_to do |format| + format.html {render @homework} + format.json {render json: @homework} + end end #显示作业信息 diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb new file mode 100644 index 00000000..073ab21b --- /dev/null +++ b/app/views/homework_attach/new.html.erb @@ -0,0 +1,33 @@ +
<%=raw l(:label_new_homework)%>
++ 标题: + <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> +
++ 描述: + + <%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +
+ + + <%= submit_tag t(:label_new), :sta => 0, :class => "enterprise"%> + <%= submit_tag t(:label_memo_create), :sta => 1, :class => "enterprise"%> + + + <% end %> +