我在我的rails項目中使用ckeditor WYSIWYG text editor。特別是:我在生產模式下配置圖片上傳時遇到問題。Rails:ckeditor gem不能在nginx和乘客的生產模式下工作
它在開發模式下工作得很好,甚至在使用Puma時在生產模式下也能工作。當我點擊上傳照片並點擊Browse Server
按鈕。它立即尋找照片,我期望他們:在/assets/ckeditor_assets/pictures
。
問題是讓它在nginx的生產模式下工作。當我在生產模式下使用nginx時:它返回一個404 Not Found
錯誤消息。我看了看我的服務器日誌,這裏是這樣說的:
「的/ var/WWW/MYAPP/CKEditor的/圖片」 失敗(2:沒有這樣的文件或目錄)
所以對於一些因爲它試圖在我的公共目錄中找到一個ckeditor
目錄(因爲這是我公共目錄的符號鏈接)。我甚至不知道爲什麼ckeditor正在尋找一個ckeditor
目錄,而不是在我的應用程序public/assets/ckeditor_assets
目錄中查找。
我試圖通過在我的公共目錄中創建一個ckeditor
目錄,然後在其中放置一個pictures
目錄來解決此問題。但是,當我這樣做時,我得到了一個403 Forbidden
錯誤。
我也注意到,在config/initializers/ckeditor.rb
文件中有這樣一行:
# Customize ckeditor assets path
# By default: nil
#config.asset_path = "http://www.example.com/assets/ckeditor/"
所以只是爲了給它一個鏡頭我硬編碼,我想CKEditor的去獲取圖片,可惜沒有工作。
任何建議,請讓我知道。謝謝!我會繼續前進,顯示情況下我ckeditor::picture
模型文件,它提供的線索:
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data,
:url => "/assets/ckeditor_assets/pictures/:id/:style_:basename.:extension",
:path => ":rails_root/public/assets/ckeditor_assets/pictures/:id/:style_:basename.:extension",
:styles => { :content => '800>', :thumb => '118x100#' }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 2.megabytes
validates_attachment_content_type :data, :content_type => /\Aimage/
def url_content
url(:content)
end
end