Sha256: 898c6c872a4952b2bc52a07cc8e7622f2674472eda2876a6975071394fdaa3f7

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

class RedactorRails::PicturesController < ApplicationController
  before_action :redactor_authenticate_user!

  def index
    @pictures = RedactorRails.picture_model.where(
        RedactorRails.picture_model.new.respond_to?(RedactorRails.devise_user) ? { RedactorRails.devise_user_key => redactor_current_user.id } : { })
    render :json => @pictures.to_json
  end

  def create
    @picture = RedactorRails.picture_model.new

    file = params[:file]
    @picture.data = RedactorRails::Http.normalize_param(file, request)
    if @picture.has_attribute?(:"#{RedactorRails.devise_user_key}")
      @picture.send("#{RedactorRails.devise_user}=", redactor_current_user)
      @picture.assetable = redactor_current_user
    end

    if @picture.save
      render json: { filelink: @picture.url(:content) }
    else
      render json: { error: @picture.errors }
    end
  end

  private

  def redactor_authenticate_user!
    if RedactorRails.picture_model.new.has_attribute?(RedactorRails.devise_user)
      super
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
redactor-rails-fixes-0.5.0.1 app/controller/redactor_rails/pictures_controller.rb
rdrails5-0.5.1 app/controller/redactor_rails/pictures_controller.rb