Class: EditorController

Inherits:
ApplicationController show all
Defined in:
app/controllers/editor_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
# File 'app/controllers/editor_controller.rb', line 5

def index
end

#load_fileObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/editor_controller.rb', line 13

def load_file
  f = params['load_file']
  mime_type = MIME.check(f.path)
  content_type = mime_type.try(:content_type) || f.content_type
  res = {
    name: f.original_filename,
    type: content_type,
    size: f.size,
  }
  if /\Atext\/plain/ =~ content_type
    res[:source] = NKF.nkf('-w', f.read)
  else
    res[:error] = 'Rubyのプログラムではありません'
  end
  render json: res, content_type: request.format
end

#save_fileObject



8
9
10
11
# File 'app/controllers/editor_controller.rb', line 8

def save_file
  send_data(params[:source], filename: params[:filename],
            disposition: 'attachment', type: 'text/plain; charset=utf-8')
end