scinote-web/app/controllers/tiny_mce_assets_controller.rb

32 lines
905 B
Ruby
Raw Normal View History

2017-04-19 15:13:16 +08:00
class TinyMceAssetsController < ApplicationController
2017-04-21 22:09:04 +08:00
before_action :find_object
2017-04-19 15:13:16 +08:00
def create
2017-04-21 22:09:04 +08:00
image = params.fetch(:file) { render_404 }
2017-04-25 19:44:31 +08:00
tiny_img = TinyMceAsset.new(image: image,
reference: @obj,
team_id: current_team.id)
2017-04-21 22:09:04 +08:00
if tiny_img.save
render json: {
2017-04-24 22:22:25 +08:00
image: {
url: view_context.image_url(tiny_img.url(:large)),
token: Base62.encode(tiny_img.id)
}
2017-04-21 22:09:04 +08:00
}, content_type: 'text/html'
else
2017-04-24 22:22:25 +08:00
render json: {
error: tiny_img.errors.full_messages
}, status: :unprocessable_entity
2017-04-21 22:09:04 +08:00
end
2017-04-19 15:13:16 +08:00
end
2017-04-19 23:22:57 +08:00
2017-04-21 22:09:04 +08:00
private
def find_object
obj_type = params.fetch(:object_type) { render_404 }
obj_id = params.fetch(:object_id) { render_404 }
2017-04-24 22:22:25 +08:00
render_404 unless %w(step result_text).include? obj_type
2017-04-21 22:09:04 +08:00
@obj = obj_type.classify.constantize.find_by_id(obj_id)
end
2017-04-19 15:13:16 +08:00
end