PerfectlyNormal / tinymce-rails-imageupload

Image upload plugin for TinyMCE and Rails with the asset pipeline
MIT License
148 stars 153 forks source link

Rails 4.2 doesnt return url #75

Closed vokshirg closed 8 years ago

vokshirg commented 8 years ago

Hi) I'm using rails 4.2.5. I was following setup instructions, but get fail. When i uploadting file - it doesn't return url in json, but my page with editor in json format. whats wrong?

 class TinymceAssetsController < ApplicationController
    respond_to :json

    def create
     geometry = Paperclip::Geometry.from_file params[:file]
     image    = Image.create params.permit(:file, :alt, :hint)
     authorize image

     render json: {
       image: {
         url:    image.file.url,
         height: geometry.height.to_i,
         width:  geometry.width.to_i
       }
     }, layout: false, content_type: "text/html"
   end
 end 

class Image < ActiveRecord::Base
  has_attached_file :file
  validates_attachment_content_type :file, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
end
sobrinho commented 8 years ago

I believe that's a problem on your controller, what happen if you do that:

def create
   geometry = Paperclip::Geometry.from_file params[:file]
   image    = Image.create params.permit(:file, :alt, :hint)
   authorize image

  raise image.file.url
end

If you do not see the URL on the exception, there is a problem with your Image model.

sobrinho commented 8 years ago

Feel free to reopen if is not that :)