文件导入导出
This commit is contained in:
parent
2c620573dd
commit
c04abd6ff7
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value />
|
||||
</option>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,30 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectInspectionProfilesVisibleTreeState">
|
||||
<entry key="Project Default">
|
||||
<profile-state>
|
||||
<expanded-state>
|
||||
<State>
|
||||
<id />
|
||||
</State>
|
||||
<State>
|
||||
<id>CSS</id>
|
||||
</State>
|
||||
<State>
|
||||
<id>Probable bugsCSS</id>
|
||||
</State>
|
||||
<State>
|
||||
<id>RELAX NG</id>
|
||||
</State>
|
||||
</expanded-state>
|
||||
<selected-state>
|
||||
<State>
|
||||
<id>CoffeeScript</id>
|
||||
</State>
|
||||
</selected-state>
|
||||
</profile-state>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
|
@ -36,19 +11,4 @@
|
|||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.2.4" project-jdk-type="RUBY_SDK" />
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ScopeChooserConfigurable.UI">
|
||||
<settings>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
|
@ -108,6 +108,25 @@
|
|||
<RAILS_SERVER_CONFIG_SETTINGS_ID NAME="LAUNCH_JS" VALUE="false" />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="false" name="product_controller" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
||||
<module name="vim" />
|
||||
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
||||
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/app/models" />
|
||||
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
||||
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
||||
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
||||
<envs />
|
||||
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
||||
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
||||
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
||||
<COVERAGE_PATTERN ENABLED="true">
|
||||
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
||||
</COVERAGE_PATTERN>
|
||||
</EXTENSION>
|
||||
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/app/models/product_controller.rb" />
|
||||
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the excel controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -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
|
||||
|
@ -79,7 +93,19 @@ class CoursesController < ApplicationController
|
|||
redirect_to courses_path, flash: flash
|
||||
end
|
||||
|
||||
def excel_out
|
||||
@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
|
||||
|
||||
def show
|
||||
@course = Course.find(params[:id])
|
||||
end
|
||||
#-------------------------for both teachers and students----------------------
|
||||
|
||||
def index
|
||||
|
@ -118,7 +144,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
|
||||
def course_params
|
||||
params.require(:course).permit(:course_code, :avatar, :name, :course_type, :teaching_type, :exam_type,
|
||||
params.require(:course).permit(:course_code, :excel, :avatar, :name, :course_type, :teaching_type, :exam_type,
|
||||
:credit, :limit_num, :class_room, :course_time, :course_week, :course_introduction)
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
=begin
|
||||
Date: 2016.12.28
|
||||
创建基于Importex::Base的类
|
||||
使用导入excel的ruby插件 importex
|
||||
gem install importex
|
||||
或者使用
|
||||
./script/plugin install git://github.com/ryanb/importex.git
|
||||
=end
|
||||
|
||||
class ExcelController < ApplicationController
|
||||
def parse
|
||||
#output excel
|
||||
respond_to :html, :xlsx
|
||||
def index
|
||||
@user = User.all
|
||||
respond_with @users
|
||||
end
|
||||
end
|
||||
|
||||
def creat
|
||||
@excel = Excel.new(excel_params)
|
||||
@book.excel.url = params[:file];
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -12,6 +12,35 @@ class GradesController < ApplicationController
|
|||
redirect_to grades_path(course_id: params[:course_id]), flash: flash
|
||||
end
|
||||
|
||||
def excel_in
|
||||
|
||||
require 'importex'
|
||||
Excel <Importex::Base
|
||||
column "Name",:required=> true
|
||||
column "class",:required=> true
|
||||
column "Grades",:type=> Integer
|
||||
column "Date",:type=> Date
|
||||
column "Discontinued",:type=> Boolean
|
||||
|
||||
#导入excel文件
|
||||
Excel.import("course.excel")
|
||||
|
||||
#使用导入数据
|
||||
#all代表所有的数据,各个字段作为hash
|
||||
excel = Excel.all
|
||||
excel.first["Discontinued"] # => false
|
||||
|
||||
#数据验证和容错处理
|
||||
#当excel的数据格式不能处理的时候,或者数据格式不符合时
|
||||
begin
|
||||
Excel.import()
|
||||
rescue Importex::ImportError => e
|
||||
puts e.message
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def index
|
||||
if teacher_logged_in?
|
||||
@course=Course.find_by_id(params[:course_id])
|
||||
|
|
|
@ -1,73 +1,73 @@
|
|||
class UsersController < ApplicationController
|
||||
before_action :logged_in, only: :update
|
||||
before_action :correct_user, only: [:update, :destroy]
|
||||
before_action :logged_in, only: :update
|
||||
before_action :correct_user, only: [:update, :destroy]
|
||||
|
||||
def new
|
||||
@user=User.new
|
||||
end
|
||||
def new
|
||||
@user=User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
if @user.save
|
||||
redirect_to root_url, flash: {success: "新账号注册成功,请登陆"}
|
||||
else
|
||||
flash[:warning] = "账号信息填写有误,请重试"
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
if @user.save
|
||||
redirect_to root_url, flash: {success: "新账号注册成功,请登陆"}
|
||||
else
|
||||
flash[:warning] = "账号信息填写有误,请重试"
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@user=User.find_by_id(params[:id])
|
||||
end
|
||||
def edit
|
||||
@user=User.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find_by_id(params[:id])
|
||||
if @user.update_attributes(user_params)
|
||||
flash={:info => "更新成功"}
|
||||
else
|
||||
flash={:warning => "更新失败"}
|
||||
end
|
||||
redirect_to root_path, flash: flash
|
||||
end
|
||||
def update
|
||||
@user = User.find_by_id(params[:id])
|
||||
if @user.update_attributes(user_params)
|
||||
flash={:info => "更新成功"}
|
||||
else
|
||||
flash={:warning => "更新失败"}
|
||||
end
|
||||
redirect_to root_path, flash: flash
|
||||
end
|
||||
|
||||
def destroy
|
||||
@user = User.find_by_id(params[:id])
|
||||
@user.destroy
|
||||
redirect_to users_path(new: false), flash: {success: "用户删除"}
|
||||
end
|
||||
def destroy
|
||||
@user = User.find_by_id(params[:id])
|
||||
@user.destroy
|
||||
redirect_to users_path(new: false), flash: {success: "用户删除"}
|
||||
end
|
||||
|
||||
|
||||
#----------------------------------- students function--------------------
|
||||
|
||||
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :major, :department, :password,
|
||||
:password_confirmation)
|
||||
end
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :major, :department, :password,
|
||||
:password_confirmation)
|
||||
end
|
||||
|
||||
# Confirms a logged-in user.
|
||||
def logged_in
|
||||
unless logged_in?
|
||||
redirect_to root_url, flash: {danger: '请登陆'}
|
||||
end
|
||||
end
|
||||
# Confirms a logged-in user.
|
||||
def logged_in
|
||||
unless logged_in?
|
||||
redirect_to root_url, flash: {danger: '请登陆'}
|
||||
end
|
||||
end
|
||||
|
||||
# Confirms the correct user.
|
||||
def correct_user
|
||||
@user = User.find(params[:id])
|
||||
unless current_user?(@user)
|
||||
redirect_to root_url, flash: {:warning => '此操作需要管理员身份'}
|
||||
end
|
||||
end
|
||||
# Confirms the correct user.
|
||||
def correct_user
|
||||
@user = User.find(params[:id])
|
||||
unless current_user?(@user)
|
||||
redirect_to root_url, flash: {:warning => '此操作需要管理员身份'}
|
||||
end
|
||||
end
|
||||
|
||||
# Confirms a logged-in user.
|
||||
def teacher_logged_in
|
||||
unless teacher_logged_in?
|
||||
redirect_to root_url, flash: {danger: '请登陆'}
|
||||
end
|
||||
end
|
||||
# Confirms a logged-in user.
|
||||
def teacher_logged_in
|
||||
unless teacher_logged_in?
|
||||
redirect_to root_url, flash: {danger: '请登陆'}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
module ExcelHelper
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
class Course < ActiveRecord::Base
|
||||
|
||||
mount_uploader :avatar, AvatarUploader
|
||||
mount_uploader :excel, ExcelUploader
|
||||
|
||||
has_many :grades
|
||||
has_many :users, through: :grades
|
||||
|
@ -10,5 +11,4 @@ class Course < ActiveRecord::Base
|
|||
validates :name, :course_type, :course_time, :course_week,
|
||||
:class_room, :credit, :teaching_type, :exam_type, presence: true, length: {maximum: 50}
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
=begin
|
||||
Date: 2016.12.28
|
||||
创建基于Importex::Base的类
|
||||
使用导入excel的ruby插件 importex
|
||||
gem install importex
|
||||
或者使用
|
||||
./script/plugin install git://github.com/ryanb/importex.git
|
||||
=end
|
||||
|
||||
|
||||
require 'importex'
|
||||
class Excel <Importex::Base
|
||||
column "Name",:required=> true
|
||||
column "class",:required=> true
|
||||
column "Grades",:type=> Integer
|
||||
column "Date",:type=> Date
|
||||
column "Discontinued",:type=> Boolean
|
||||
end
|
||||
|
||||
#导入excel文件
|
||||
Excel.import("course.excel")
|
||||
|
||||
#使用导入数据
|
||||
#all代表所有的数据,各个字段作为hash
|
||||
excel = Excel.all
|
||||
excel.first["Discontinued"] # => false
|
||||
|
||||
#数据验证和容错处理
|
||||
#当excel的数据格式不能处理的时候,或者数据格式不符合时
|
||||
begin
|
||||
Excel.import()
|
||||
rescue Importex::ImportError => e
|
||||
puts e.message
|
||||
end
|
||||
|
||||
|
||||
#允许导入的字段指向Ruby对象,
|
||||
# 例如,下面的例子,可以增加一个字段表示上面导入Product的类型情况
|
||||
class Category < ActiveRecord::Base
|
||||
def self.importex_value(str)
|
||||
find_by_name!(str)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
raise Importex::InvalidCell, "No category with that name."
|
||||
end
|
||||
end
|
||||
|
||||
class Product < Importex::Base
|
||||
column "Category", :type => Category
|
||||
end
|
|
@ -0,0 +1,53 @@
|
|||
=begin
|
||||
用Ruby读取Excel文件
|
||||
Parseexcel是一个ruby端的perl解析excel的插件
|
||||
=end
|
||||
|
||||
Spreadsheet::Parseexcel.parse("course.excel")
|
||||
worksheet = workbook.worksheet(0)
|
||||
worksheet.each { |row|
|
||||
j = 0
|
||||
i = 0
|
||||
if row != nil
|
||||
row.each { |cell|
|
||||
if cell != nil
|
||||
contents = cell.to_s('latin1')
|
||||
puts "Row: #{j} Cell: #{i} #{contents}"
|
||||
end
|
||||
i = i+1
|
||||
}
|
||||
j = j +1
|
||||
end
|
||||
}
|
||||
|
||||
=begin
|
||||
cell.to_s('latin1') #读取字符串
|
||||
cell.to_s('latin1') #读取float值
|
||||
cell.to_i #读取int值
|
||||
cell.date #读取一个时间值
|
||||
cell = row.at(3) #读取特定值
|
||||
=end
|
||||
|
||||
require 'parseexcel'
|
||||
|
||||
#从命令行输入要打开的excel文件名
|
||||
workbook = Spreadsheet::ParseExcel.parse(ARGV[0])
|
||||
|
||||
#得到第一个表单
|
||||
worksheet = workbook.worksheet(0)
|
||||
#遍历行
|
||||
worksheet.each { |row|
|
||||
j=0
|
||||
i=0
|
||||
if row != nil
|
||||
#遍历该行非空单元格
|
||||
row.each { |cell|
|
||||
if cell != nil
|
||||
#取得单元格内容为string类型
|
||||
contents = cell.to_s('latin1')
|
||||
puts "Row: #{j} Cell: #{i}> #{contents}"
|
||||
end
|
||||
i = i+1
|
||||
}
|
||||
end
|
||||
}
|
|
@ -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
|
|
@ -113,6 +113,17 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.label "excel", class: 'col-sm-3 control-label' %>
|
||||
<div class="col-sm-9">
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><span class="glyphicon glyphicon-arrow-right"></span></div>
|
||||
<%= f.file_field :excel %>
|
||||
<%= f.hidden_field :excel_cache %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<%= render "shared/sidenav" %>
|
||||
|
||||
</div>
|
||||
<div class="col-sm-10">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
|
||||
</div>
|
||||
<div class="panel-body" style="min-height: 450px">
|
||||
<table class="table table-striped table-hover">
|
||||
|
||||
<thead>
|
||||
|
||||
<caption></caption>
|
||||
<tr>
|
||||
<th align="center" >课程名称</th>
|
||||
<th align="right">Excel文件导入</th>
|
||||
</tr>
|
||||
</tablebotder>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<% @course.each do |course| %>
|
||||
<tr>
|
||||
<td align="left" ><%= link_to course.name, detail_course_url(course), class: 'btn-sm' %></td>
|
||||
<!--<a href="link_to course.excel"></a>-->
|
||||
<!--<td align="left"><%= link_to course.excel, detail_course_path(course), class: 'btn-sm' %></td>-->
|
||||
|
||||
<%= form_for course, url: excel_in_course_path(course) , html: {class: 'form-horizontal', role: 'form'} do |f| %>
|
||||
<div class="form-group">
|
||||
<%= f.label "上传文件", class: 'col-sm-3 control-label' %>
|
||||
<div class="col-sm-3">
|
||||
<div class="input-group">
|
||||
<%= f.file_field :excel %>
|
||||
<%= f.hidden_field :excel_cache %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%= f.submit '提交', class: "btn btn-success btn-block" %>
|
||||
<% end %>
|
||||
<td><a class="btn btn-xs btn-success" href=<%="http://localhost:3000#{course.excel}"%> >下载最新资料</a></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<button id="downloadBt" style= "width:80px;height:25px;padding:2px;font-size:13px;color:black;left:90%; top:69%;position:absolute;z-index:100" onclick="downloadSchedule()">下载表格</button>
|
||||
</div>
|
||||
|
||||
<!--<script src="../src/jquery.min.js"></script>-->
|
||||
<!--<script src="../src/jquery.table2excel.js"></script>-->
|
||||
<script>
|
||||
function downloadSchedule() {
|
||||
$(".table2excel").table2excel({
|
||||
exclude: ".noExl",
|
||||
name: "Excel Document Name",
|
||||
filename: "<%= current_user.name %>课表",
|
||||
fileext: ".xls",
|
||||
exclude_img: true,
|
||||
exclude_links: true,
|
||||
exclude_inputs: true
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
<td><%= course.credit %></td>
|
||||
<td><%= course.exam_type %></td>
|
||||
<td><%= course.teacher.name %></td>
|
||||
<td><%course.excel%></td>
|
||||
|
||||
<% if teacher_logged_in? %>
|
||||
<td><%= link_to "编辑", edit_course_url(course), class: 'btn btn-xs btn-info' %></td>
|
||||
|
@ -46,7 +47,10 @@
|
|||
<td><%= link_to "删除", course_path(course), :method => "delete", class: 'btn btn-xs btn-danger', :data => {confirm: '确定要删除此课程?'} %></td>
|
||||
<% elsif student_logged_in? %>
|
||||
<td><%= link_to "删除", quit_course_path(course), class: 'btn-sm btn-danger' %></td>
|
||||
<td><a class="btn btn-xs btn-success" href=<%="http://localhost:3000#{course.excel}"%> >下载最新资料</a></td>
|
||||
<% end %>
|
||||
|
||||
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -56,4 +60,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
<h1>Hello,Rails</h1>
|
||||
<p>Find me in app/views/excel/parse.html.erb</p>
|
|
@ -34,7 +34,65 @@
|
|||
<td><%= grade.user.department %></td>
|
||||
<td><%= grade.course.name %></td>
|
||||
<td><%= grade.grade %></td>
|
||||
<!--
|
||||
<td><%= grade.course.excel %></td>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>JavaScript遍历table</title>
|
||||
<style type="text/css">
|
||||
tr td,tr th{
|
||||
border:#CCC 1px solid;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
/**
|
||||
* JavaScript遍历table
|
||||
*/
|
||||
function eachTableRow()
|
||||
{
|
||||
//获取table序号
|
||||
var tab=document.getElementById("course.excel");
|
||||
//获取行数
|
||||
var rows=tab.rows;
|
||||
//遍历行
|
||||
for(var i=1;i<rows.length;i++)
|
||||
{
|
||||
//遍历表格列
|
||||
for(var j=0;j<rows[i].cells.length;j++)
|
||||
{
|
||||
//打印某行某列的值
|
||||
alert("第"+(i+1)+"行,第"+(j+1)+"列的值是:"+rows[i].cells[j].innerHTML);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table id="tab" cellpadding="0" cellspacing="0" style="width:50%; text-align:center; border:#CCC 1px solid;">
|
||||
<tr style="border:#CCC 1px solid;">
|
||||
<th>学号</th>
|
||||
<th>姓名</th>
|
||||
<th>年龄</th>
|
||||
<th>性别</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2014010101</td>
|
||||
<td>张思思</td>
|
||||
<td>20</td>
|
||||
<td>女</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2014010102</td>
|
||||
<td>立三</td>
|
||||
<td>21</td>
|
||||
<td>男</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<input type="button" value="遍历" onclick="eachTableRow()"/>
|
||||
</body>
|
||||
-->
|
||||
<% if teacher_logged_in? %>
|
||||
<%= form_for grade, url: grade_url(id: grade.id, course_id: grade.course.id), method: :patch do |f| %>
|
||||
<td><%= f.text_field :grade %></td>
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
<% if teacher_logged_in? %>
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#GradeCollapse"><span class="glyphicon glyphicon-user"></span>
|
||||
成绩管理</a>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% if student_logged_in? %>
|
||||
|
@ -72,6 +73,12 @@
|
|||
<div class="list-group">
|
||||
|
||||
<% if teacher_logged_in? %>
|
||||
<li class="list-group-item">
|
||||
<%= link_to excel_courses_path do %>
|
||||
<span class="glyphicon glyphicon-chevron-right"></span> excel
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<% current_user.teaching_courses.each do |course| %>
|
||||
<li class="list-group-item">
|
||||
<%= link_to grades_path(course_id: course.id), :method => :get do %>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
Rails.application.routes.draw do
|
||||
get 'excel/parse'
|
||||
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
# See how all your routes lay out with "rake routes".
|
||||
|
||||
|
@ -24,9 +26,12 @@ Rails.application.routes.draw do
|
|||
get :detail
|
||||
get :open
|
||||
get :close
|
||||
patch :excel_in
|
||||
patch :excel_out
|
||||
end
|
||||
collection do
|
||||
get :list
|
||||
get :excel
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddExcelToCourse < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :courses, :excel, :string
|
||||
end
|
||||
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20161108164630) do
|
||||
ActiveRecord::Schema.define(version: 20161228082748) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -29,10 +29,12 @@ ActiveRecord::Schema.define(version: 20161108164630) do
|
|||
t.string "course_time"
|
||||
t.string "course_week"
|
||||
t.integer "teacher_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 "course_introduction"
|
||||
t.string "avatar"
|
||||
t.boolean "open", default: false
|
||||
t.string "excel"
|
||||
end
|
||||
|
||||
create_table "grades", force: :cascade do |t|
|
||||
|
@ -46,12 +48,6 @@ ActiveRecord::Schema.define(version: 20161108164630) do
|
|||
add_index "grades", ["course_id"], name: "index_grades_on_course_id", using: :btree
|
||||
add_index "grades", ["user_id"], name: "index_grades_on_user_id", using: :btree
|
||||
|
||||
create_table "images", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "image"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 251 KiB |
|
@ -0,0 +1 @@
|
|||
RM-162.2380.8
|
Binary file not shown.
After Width: | Height: | Size: 198 KiB |
Binary file not shown.
After Width: | Height: | Size: 99 KiB |
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ExcelControllerTest < ActionController::TestCase
|
||||
test "should get parse" do
|
||||
get :parse
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue