分离模型验证?

时间:2014-10-15 20:13:51

标签: ruby-on-rails activerecord ruby-on-rails-4

所以我有一个带有后端管理仪表板的应用程序,允许管理员上传旋转轮播的Slider图像。索引页面上的旋转轮播(登录时)和登录页面时(退出时)。

问题是着陆页和索引图片上传都共享相同的维度验证,但是,我想为目标网页和索引页面设置不同的大小。我想以某种方式通过分离字段或通过其他一些有效手段来实现这一点。

有什么想法吗?请参阅下面的当前代码:

class Slider < ActiveRecord::Base
  validates :short_text, presence: true

  has_attached_file :image, styles: {
      medium: '800x>',
      small: '300x>'
  }

  validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
  validates :image, dimensions: { width: 1024, height: 427 }, on: :create

  SLIDER_TYPES = {
    0 => "Both (Landing and Index page)",
    1 => "Landing Page",
    2 => 'Index Page'
  }
end

0 个答案:

没有答案