This commit is contained in:
parent
6b8e2e293f
commit
fe4b834b96
|
@ -57,6 +57,20 @@ class CoursesController < ApplicationController
|
|||
redirect_to courses_path, flash: {:success => "已经成功关闭该课程:#{ @course.name}"}
|
||||
end
|
||||
|
||||
def excel
|
||||
@course= current_user.teaching_courses
|
||||
end
|
||||
|
||||
def excel_in
|
||||
@course = Course.find_by_id(params[:id])
|
||||
if @course.update_attributes(course_params)
|
||||
flash={:info => " 导入成功"}
|
||||
else
|
||||
flash={:warning => "导入失败"}
|
||||
end
|
||||
redirect_to excel_courses_path, flash: flash
|
||||
end
|
||||
|
||||
#-------------------------for students----------------------
|
||||
|
||||
def list
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Course < ActiveRecord::Base
|
||||
|
||||
mount_uploader :avatar, AvatarUploader
|
||||
mount_uploader :excel, ExcelUploader
|
||||
|
||||
has_many :grades
|
||||
has_many :users, through: :grades
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
# encoding: utf-8
|
||||
|
||||
class ExcelUploader < CarrierWave::Uploader::Base
|
||||
|
||||
# Include RMagick or MiniMagick support:
|
||||
# include CarrierWave::RMagick
|
||||
# include CarrierWave::MiniMagick
|
||||
|
||||
# Choose what kind of storage to use for this uploader:
|
||||
storage :file
|
||||
# storage :fog
|
||||
|
||||
# Override the directory where uploaded files will be stored.
|
||||
# This is a sensible default for uploaders that are meant to be mounted:
|
||||
def store_dir
|
||||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
||||
end
|
||||
|
||||
# Provide a default URL as a default if there hasn't been a file uploaded:
|
||||
# def default_url
|
||||
# # For Rails 3.1+ asset pipeline compatibility:
|
||||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
||||
#
|
||||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
||||
# end
|
||||
|
||||
# Process files as they are uploaded:
|
||||
# process :scale => [200, 300]
|
||||
#
|
||||
# def scale(width, height)
|
||||
# # do something
|
||||
# end
|
||||
|
||||
# Create different versions of your uploaded files:
|
||||
# version :thumb do
|
||||
# process :resize_to_fit => [50, 50]
|
||||
# end
|
||||
|
||||
# Add a white list of extensions which are allowed to be uploaded.
|
||||
# For images you might use something like this:
|
||||
# def extension_white_list
|
||||
# %w(jpg jpeg gif png)
|
||||
# end
|
||||
|
||||
# Override the filename of the uploaded files:
|
||||
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
||||
# def filename
|
||||
# "something.jpg" if original_filename
|
||||
# end
|
||||
|
||||
end
|
|
@ -28,6 +28,7 @@
|
|||
<th>编辑课程</th>
|
||||
<th>打开课程</th>
|
||||
<th>删除课程</th>
|
||||
<th>上传最新资料</th>
|
||||
<% elsif student_logged_in? %>
|
||||
<th>删除课程</th>
|
||||
<th>是否选为学位课</th>
|
||||
|
@ -52,6 +53,11 @@
|
|||
<td><%= link_to "打开", open_course_url(course), class: 'btn btn-xs btn-info' %></td>
|
||||
<% end %>
|
||||
<td><%= link_to "删除", course_path(course), :method => "delete", class: 'btn btn-xs btn-danger', :data => {confirm: '确定要删除此课程?'} %></td>
|
||||
|
||||
<td><%= f.file_field :excel %>
|
||||
<%= f.hidden_field :excel_cache %></td>
|
||||
|
||||
|
||||
<% elsif student_logged_in? %>
|
||||
<td><%= link_to "删除", quit_course_path(course), class: 'btn-sm btn-danger' %></td>
|
||||
<% if course.degree %>
|
||||
|
|
|
@ -27,12 +27,15 @@ Rails.application.routes.draw do
|
|||
get :classtable
|
||||
get :isdegree #add route isdegree
|
||||
get :nodegree #add route nodegree
|
||||
patch :excel_in
|
||||
patch :excel_out
|
||||
end
|
||||
collection do
|
||||
get :list
|
||||
get :search
|
||||
get :refresh_search
|
||||
get :credit #add credit route
|
||||
get :excel
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddNewfileToCourse < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :courses, :excel, :string
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue