如何根据图片模型在Ruby On Rails中的CKeditor中设置图像的大小? [英] How to set the size of an image within CKeditor in Ruby On Rails according to the picture model?

查看:103
本文介绍了如何根据图片模型在Ruby On Rails中的CKeditor中设置图像的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个重复的问题,但我对此表示怀疑。

我有以下情况:

我在红宝石上使用了两种广泛使用的宝石:回形针和ckeditor(正在使用回形针)。

I have a ruby on rails apllication with two widely used gems: paperclip and ckeditor (which is working with paperclip).

我希望根据发布的类型调整在Ckeditor屏幕中上传的图像的大小。现在,虽然C确实上传了我在picture.rb模型中设置的不同类型的尺寸,但在Ckeditor或其他任何产品中都没有一个按钮可以帮助解决此问题。

I want the size of the image that I upload in the Ckeditor screen to be resized depending on the type of 'post'. Right now there's not a button that can help with that in the Ckeditor or anything, though it does upload the different type of sizes I set in the picture.rb model:

class Ckeditor::Picture < Ckeditor::Asset
  has_attached_file :data,
                :url  => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
                :path => ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
                :styles => { :content => '600>',:medium => '300x300', :quintet => '150x150', :thumb => '118x100#' }


  validates_attachment_size :data, :less_than => 2.megabytes
  validates_attachment_presence :data


  def url_content
    url(:content)
  end
end

问题是从Ckeditor保存的内容(图像和标签)将显示为

The problem is that the content (images and tags) that gets saved from the Ckeditor will be displayed like

.post_body= raw post.content

其中post.content =

where post.content =

 <p><img alt="" src="/ckeditor_assets/pictures/2/content_cartoon_paul-the-good-fight.gif" /></p>

CKeditor使用的图像是标准图像,而不是具有特定尺寸或类型的图像。
如何设置大小或类型?

The image that the CKeditor is using is the standard image and not the image with a certain size or type. How do I set that size or type?

推荐答案

在url_content方法中,将:content替换为您的样式要求(例如:: medium,:quintet,:thumb)。请注意,对于在设置特定样式之前上传的任何图像,将没有该尺寸的相应图像。上传的所有图片都会将不同的版本保存到ckeditor_assets路径(例如原始,中型,拇指),然后您可以更改url参数以指向正确的版本。因为我正在测试已经上传的图片,所以花了一段时间才意识到这一点,因此在测试它是否可行时,请确保指定了所需的所有样式,然后上传新图片。这样便可以更改url_content的参数。

In the url_content method, replace :content with the style you require (e.g., :medium, :quintet, :thumb). Note that for any images uploaded BEFORE you set a specific style, there will be no corresponding image of that size. Any image uploaded will get different versions saved to the ckeditor_assets path (e.g., original, medium, thumb) and then you can change the url parameter to point to the correct version. It took me a while to realize this since I was testing with an already uploaded picture, so when testing if it works, make sure all the styles you want are specified and then upload a new picture. Changing the parameter for url_content should work then.

这篇关于如何根据图片模型在Ruby On Rails中的CKeditor中设置图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆