Ruby on rails 4 回形针:在后处理回调中指定附件字段
我有一个这样的模型:Ruby on rails 4 回形针:在后处理回调中指定附件字段,ruby-on-rails-4,paperclip,Ruby On Rails 4,Paperclip,我有一个这样的模型: class Attachment < ActiveRecord::Base has_attached_file :foo has_attached_file :bar end 但此回调将同时对:foo和:bar运行 如何实现这一点?根据回形针,您应该能够在bar\U post\U处理之前使用回调,如果返回falsebar的后处理将停止: class Attachment < ActiveRecord::Base has_attached_fi
class Attachment < ActiveRecord::Base
has_attached_file :foo
has_attached_file :bar
end
但此回调将同时对:foo
和:bar
运行
如何实现这一点?根据回形针,您应该能够在bar\U post\U处理之前使用回调,如果返回false
bar的后处理将停止:
class Attachment < ActiveRecord::Base
has_attached_file :foo
has_attached_file :bar
before_bar_post_process check_bar_condition
def check_bar_condition
...
return false if #some_condition_fails
...
end
end
类附件
class Attachment < ActiveRecord::Base
has_attached_file :foo
has_attached_file :bar
before_bar_post_process check_bar_condition
def check_bar_condition
...
return false if #some_condition_fails
...
end
end