Non-ActiveRecord Objects에 validate
1312 단어 ActiveRecordF#HTML
Active Record 대상이 아닌Validation에 대해 간단한include Active Record::Validations는 모듈을 써서lib 아래에 놓고validateable를 만들어야 합니다.rb
module Validateable
[:save, :save!, :update_attribute].each{|attr| define_method(attr){}}
def method_missing(symbol, *params)
if(symbol.to_s =~ /(.*)_before_type_cast$/)
send($1)
end
end
def self.append_features(base)
super
base.send(:include, ActiveRecord::Validations)
end
end
그리고 모델 밑에 있어요.
class Logo < ActiveRecord::Base
include Validateable
attr_accessor :size
validates_presence_of :size
validates_presence_of :name
file_column :photo, :magick => {
:versions => { "thumb" => "235x90>", "medium" => "640x480>" }
}
end
페이지
{:action => :create},:html => {:multipart => true} do |f| %>
name:
size:
마지막 공백 제출, 오류 보고
There were problems with the following fields:
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Rails】일대일대다의 어소시에이션결국은 기본적인 것입니다만, 조금 바뀌면 곧바로 빠져 버린다. 어소시에이션이 잘 되지 않고 시간을 녹여 버렸기 때문에, 그런 과거의 자신과 있을지도 모르는 미래의 누군가를 위해서 남겨 둡니다. User 모델과 Tag...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.