Sha256: 5c28ad22310da042b906c8edeeebf3c4a1b97681ef075f634ecaa232ecedeaad
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
class Redactor3Rails::FilesController < Redactor3Rails.base_controller include ActionView::Helpers::NumberHelper skip_before_action :verify_authenticity_token before_action :redactor3_authenticate_user! def create json = {} error = nil params[:file].each_with_index do |file, i| @file = Redactor3Rails.file_model.new @file.data = Redactor3Rails::Http.normalize_param(file, request) if @file.has_attribute?(:"#{Redactor3Rails.devise_user_key}") @file.send("#{Redactor3Rails.devise_user}=", redactor3_current_user) @file.assetable = redactor3_current_user end @file.custom_file_name = file.original_filename if @file.save json["file-#{i}"] = { id: @file.id, url: @file.url, name: @file.filename, size: number_to_human_size(@file.data_file_size) } else error = @file.errors end end if json.empty? json = { error: true, message: error.full_messages.to_sentence } end render json: json end def index json = Redactor3Rails.file_model.where(user_id: redactor3_current_user.id).order('id DESC').map do |file| { title: file.custom_file_name, size: number_to_human_size(file.data_file_size), url: file.url, id: file.id } end render json: json end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redactor3_rails-0.1.4 | app/controller/redactor3_rails/files_controller.rb |