根据README for the CKEditor gem,我应该能够为图像和附件设置替代范围。我试图这样做,它只是将它转换为ckeditor_assets表中的一个字段。
我可以创建一个迁移来添加必填字段,但是如何配置ckeditor(可能是通过自动生成的模型),以便在创建新记录时使用正确的数据填充该字段?
答案 0 :(得分:2)
解决。
我使用了before_save过滤器来设置我想要的字段。然后在应用程序控制器中更改方法以将该字段用作范围。
# models/ckeditor/asset.rb
before_save :set_company_id
def set_company_id
self.company_id = assetable.try(:company_id)
end
# controllers/application_controller.rb
protected
def ckeditor_pictures_scope(options = { :company_id => "#{company_id}" })
ckeditor_filebrowser_scope(options)
end
def ckeditor_attachment_files_scope(options = { :company_id => "#{company_id}" })
ckeditor_filebrowser_scope(options)
end
答案 1 :(得分:0)
在我看来最简单的解决方案:
#controllers/application_controller.rb
protected
def ckeditor_pictures_scope(options = { :assetable_id => "#{current_page.id}" ,:assetable_type => "Page" })
ckeditor_filebrowser_scope(options)
end
def ckeditor_attachment_files_scope(options = { :assetable_id => "#{current_page.id}" ,:assetable_type => "Page" })
ckeditor_filebrowser_scope(options)
end
def ckeditor_before_create_asset(asset)
asset.assetable = current_page if current_page
return true
end