38 lines
999 B
Ruby
38 lines
999 B
Ruby
#coding=utf-8
|
|
require 'tempfile'
|
|
require "base64"
|
|
|
|
class SolutionsController < ApplicationController
|
|
protect_from_forgery :except => :create
|
|
respond_to :html, :xml, :json
|
|
def index
|
|
@solutions = Solution.order('id desc')
|
|
respond_with @solutions
|
|
end
|
|
|
|
def new
|
|
@solution = Question.find(params[:question_id]).solutions.build
|
|
end
|
|
|
|
def create
|
|
@solution = Question.find(params[:question_id]).solutions.build
|
|
@solution.src = Base64.decode64(params[:src])
|
|
@solution.student_work_id = parmas[:student_work_id]
|
|
@solution.status = 7
|
|
respond_to do |format|
|
|
if @solution.save
|
|
#@solution.delay.work
|
|
@solution.work
|
|
format.html {redirect_to question_solutions_path(params[:question_id]),notice: '答题成功'}
|
|
format.json { render :json => @solution}
|
|
else
|
|
format.html {render :new}
|
|
format.json {render :json => @solution.errors.full_messages}
|
|
logger.error @solution.errors.full_messages
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
|