CKeditor in rails_admin - ruby-on-rails

Where I can find my images in rails app folders? I upload them by CKeditor and doesn't know where are they.
https://github.com/sferik/rails_admin

You'll need to create a model to handle the image uploads, typically with the likes of Paperclip or Carrierwave
From CKEditor's Github:
For files uploading support you need generage models for file storage.
Currently supported next backends:
ActiveRecord (paperclip, carrierwave, dragonfly)
Mongoid (paperclip, carrierwave, dragonfly)
Image Upload Model
You'll have a CKEditor model directory (with attachment_file.rb inside) - just add Paperclip options for it. Here's a question which will show you what to do: How exactly DO you integrate ckeditor with Paperclip so it can upload image files?
Yes you can. I assume that you have paperclip already set up for S3.
So you have only edit the picture.rb and attachement_file.rb in you
model directory (app/model/ckeditor/) and replace these lines
has_attached_file :data,
:url => "/ckeditor_assets/attachments/:id/:filename",
:path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename" with
your papeclip version has_attached_file:
has_attached_file :data, :styles => { :content => '575>', :thumb =>
'80x80#' },
:storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => ":attachment/:id/:style.:extension",
:url => ":s3_domain_url" That's it. Btw: this is example from Rails 3.

Related

Rails video uploading

I've searched around for different uploading options for rails and video and Paperclip seems to be pretty good, but are there any others people would recommend, it should have good tutorials and docs because i can't really find any great paperclip docs involving uploading video content.
We got Paperclip working with video a while back
Systems
You'll have the same ambiguity whether you use CarrierWave or Paperclip (Rails' two main "attachment" handlers)
Any upload system only handles the transfer of file data between your PC, your Rails app & your db. Each of them (from my understanding). E.G Paperclip only creates an ActiveRecord object from your file, saves the data to your server's public dir & creates a record in your db
Code
The question of video is one of using the right processor, rather than the right uploader:
#app/models/attachment.rb
has_attached_file :attachment,
styles: lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"} : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
processors: lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }
Extra
You'll need to use a video processor such as ffmpeg for Paperclip:
#GemFile
gem "paperclip-ffmpeg", "~> 1.0.1"
You may have to install ffmpeg on your system to get the processor to work locally (Heroku has ffmpeg). This will allow you to use the video_tag helper:
<%= video_tag(#model.attachment.url) %>
There's a good tutorial about using ffmpeg with Paperclip here
And another tutorial here
With rails Carrierwave and Paperclip are the best attachment handlers. Now
for all kinds of file upload like images, videos, other raw files etc. you can use Cloudinary with carrierwave. See this
http://cloudinary.com/documentation/rails_carrierwave

Paperclip: Isn't creating the thumb folder?

I'm using the paperclip gem (3.0.4) which suddenly stopped working as it is no longer creating the thumb folder, only original. Because of this my code can't find the image that was uploaded and errors out.
In my model I have:
has_attached_file :image,
:whiny => false,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename",
:styles => { :thumb => "150x100#" }
This code hasn't changed, and when I attempt to render my view I get the following error:
/public/system/images/52/thumb/2011-03-16_07-49-52_412.jpg not found
Looking in my file system I have, /public/system/images/52/original/2011-03-16_07-49-52_412.jpg
Could this be an issue with ImageMagick?
Any idea what is causing this and how to resolve it to ensure the thumb folder is being created? Thanks for your time and assistance.

Rails / Paperclip: How do I display images from S3 that have authenticated_read permissions?

Using Rails 3.2.1 and Paperclip 2.6
I have Paperclip set to use s3 as storage. I would like to use :s3_permissions => :authenticated_read.
Before Paperclip updated to use aws-sdk, I used the paperclip-aws gem that provides a helper for authenticated access.
Does Paperclip provide a similar helper? How do I access the images through an image_tag if they are set to authenticated_read in the absence of the paperclip-aws gem?
Given an attachment configured like so:
has_attached_file :attachment,
:storage => :s3,
:bucket => 'MY-BUCKET',
:s3_permissions => :authenticated_read,
:s3_credentials => Rails.root.join("config/aws.yml")
You can just call the #expiring_url method on your attachment:
record.attachment.expiring_url #=> "https..."
Here is the signature for #expiring_url:
def expiring_url(time = 3600, style_name = default_style)
This allows you to override the expiration time and specify what "style" or version you want a url for.

Paperclip and S3: Multiple thumbnail sizes not saving

I'm using Paperclip to handle image uploads for my Rails app, and it's working great when I use system storage: multiple thumbnail sizes ("styles" in Paperclip parlance) are saved to file, and I can access any of them by passing the style name to the url method.
When I set up the app to store images on S3 (using the aws-s3 gem), however, only one image is stored in my S3 bucket. For what it's worth, only the last style listed is stored. So, if in my model, I've got:
has_attached_file :photo,
:styles => { :large => "1000x1000>",
:medium => "600x600>",
:thumb => "200x200>" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:bucket => AppConstants.bucket,
:path => "pictures/:id/:filename"
Only the "thumb" size will be saved to S3.
Has anybody encountered a similar problem? How can I fix this?
I'm not sure why this works locally, but you didn't specify :style in your path declaration.

Ruby on Rails / Paperclip / AWS::S3::NoSuchBucket error

I installed the paperclip plugin and was able to use it locally. When I configured it to work with amazon S3 I keep getting the NoSuchBucket (The specified bucket does not exist) error. Paperclip documentation states that the bucket will be created if it doesn't exist but clearly
something is going wrong in my case.
I first insalled aws-s3 gem (v0.6.2)
then also installed right_aws gem (v1.9.0)
both have corresponding
config.gem "aws-s3", :lib => "aws/s3"
config.gem 'right_aws', :version => '1.9.0'
lines in environment.rb file
The code for the image.rb file with paperclip is as follows:
class Image < ActiveRecord::Base
belongs_to :work
has_attached_file :photo, :styles => {:big => "612x1224>", :small => "180X360>", :thumb => "36x36#"},
:storage => 's3',
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV],
:path => ":attachment/:id/:style/:basename.:extension",
:bucket => 'my-unique-image-bucket'
attr_protected :photo_file_name, :photo_content_type, :photo_size
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 3.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/gif']
end
I'm not entirely sure this is it, but your loading of the s3_credentials is different than what I'm using on my production sites.
My config line is:
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml"
Instead of
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV]
it should create but the bucket but this was a bug at one point :
http://groups.google.com/group/paperclip-plugin/browse_thread/thread/42f148cee71a0477
i recently had this problem and it turned out to be the servers time was hugely off and s3 wouldnt allow any updates "that far in the future" or similar but the rails error was NoSuchBucket...confusing
..
I have installed the s3fox plugin for firefox and created the bucket with the plugin. Now Paperclip works fine with S3 as the bucket identified is already created.
But I am still curious about paperclip's inability to create new buckets with the code above.
In case anyone winds up here via google: I saw this same error when I mistakenly switched the order of the 2nd and 3rd parameters I was passing to AWS::S3::S3Object.store.
It's not your case, but AWS doesn't allow upper case letters in bucket name and paperclip doesn't check that, failing in create_bucket.

Resources