对于一个项目,我需要能够将视频上传到视频服务器。 起初,范围只是上传到Kaltura视频服务器。 为了实现这一点,我创建了一个简单的关注点,它为处理上传的模型添加了一些回调方法。
这些回调方法(特别是对于Kaltura)正在加载如下:
class Videofile < ActiveRecord::Base include KalturaBox::Entry end它们包含这样的基础知识(简化版):
module KalturaBox module Entry extend ActiveSupport::Concern included do before_save :create_kaltura_item, on: :create private def create_kaltura_item puts 'create callback called' self.upload end end end现在范围已经扩大,我被要求也包括Vimeo上传作为选项。
是否可以根据模型的属性动态嵌入关注点,还是应该考虑使用STI?
我正在考虑创建一个名为“video_type”的下拉列表。 如何根据该属性包含正确的代码?
For a project I needed the ability to upload video's to a video server. At first the scope was to only upload to a Kaltura video server. To enable this, I created a simple concern that added some callback methods to the model which handle the uploads.
These callback methods (specifically for Kaltura) are being loaded like so:
class Videofile < ActiveRecord::Base include KalturaBox::Entry endAnd they contain basics like this (simplified version):
module KalturaBox module Entry extend ActiveSupport::Concern included do before_save :create_kaltura_item, on: :create private def create_kaltura_item puts 'create callback called' self.upload end end endNow the scope has broadened, and I was asked to also include Vimeo uploads as an option.
Is it possible to dynamically embed the concerns based on an attribute of the model, or should I consider using STI instead?
I was thinking about creating a drop-down called "video_type". How do I include the correct code based on that attribute?
最满意答案
我正在考虑创建一个名为“video_type”的下拉列表。 如何根据该属性包含正确的代码?
使用条件回调 。
before_save :create_kaltura_item, on: :create, if: :kaltura? def kaltura? video_type == 'kaltura' end这样您就可以静态地包含这两个问题。
I was thinking about creating a drop-down called "video_type". How do I include the correct code based on that attribute?
Use conditional callbacks.
before_save :create_kaltura_item, on: :create, if: :kaltura? def kaltura? video_type == 'kaltura' endThis way you can include both concerns statically.
更多推荐
发布评论