Merge branch 'add-formData-support' of https://github.com/thg303/rswag into thg303-add-formData-support

This commit is contained in:
domaindrivendev
2017-07-21 14:25:29 -07:00
12 changed files with 125 additions and 27 deletions

View File

@@ -1,3 +1,5 @@
require 'fileutils'
class BlogsController < ApplicationController
# POST /blogs
@@ -6,6 +8,14 @@ class BlogsController < ApplicationController
respond_with @blog
end
# Put /blogs/1
def upload
@blog = Blog.find_by_id(params[:id])
return head :not_found if @blog.nil?
@blog.thumbnail = save_uploaded_file params[:file]
head @blog.save ? :ok : :unprocsessible_entity
end
# GET /blogs
def index
@blogs = Blog.all
@@ -22,4 +32,13 @@ class BlogsController < ApplicationController
respond_with @blog, status: :not_found and return unless @blog
respond_with @blog
end
private
def save_uploaded_file(field)
return if field.nil?
file = File.join('tmp', field.original_filename)
FileUtils.cp field.tempfile.path, file
field.original_filename
end
end

View File

@@ -5,7 +5,8 @@ class Blog < ActiveRecord::Base
{
id: id,
title: title,
content: nil
content: nil,
thumbnail: thumbnail
}
end
end