Moving to activemodel validations
This commit is contained in:
parent
b9bff76054
commit
40120bb441
3 changed files with 16 additions and 20 deletions
3
Gemfile
3
Gemfile
|
|
@ -8,8 +8,7 @@ gem 'bundler', '1.0.0'
|
|||
gem 'devise', :git => 'http://github.com/BadMinus/devise.git'
|
||||
|
||||
#Mongo
|
||||
gem 'mongo_mapper', '0.8.4', :git => 'http://github.com/jnunemaker/mongomapper.git'
|
||||
gem 'jnunemaker-validatable', '1.8.4', :git => 'http://github.com/jnunemaker/validatable.git'
|
||||
gem 'mongo_mapper', :branch => 'rails3', :git => 'http://github.com/jnunemaker/mongomapper.git'
|
||||
gem 'bson_ext', '1.0.7'
|
||||
gem 'bson', '1.0.7'
|
||||
|
||||
|
|
|
|||
17
Gemfile.lock
17
Gemfile.lock
|
|
@ -57,20 +57,14 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: http://github.com/jnunemaker/mongomapper.git
|
||||
revision: 931dab779011aa7acf60c1a4c7ad19e1ba838345
|
||||
revision: b0eac421ef5b3bee782e15d391eca372a189d414
|
||||
branch: rails3
|
||||
specs:
|
||||
mongo_mapper (0.8.4)
|
||||
activesupport (>= 2.3.4)
|
||||
jnunemaker-validatable (~> 1.8.4)
|
||||
activemodel (~> 3.0.0)
|
||||
activesupport (~> 3.0.0)
|
||||
plucky (~> 0.3.5)
|
||||
|
||||
GIT
|
||||
remote: http://github.com/jnunemaker/validatable.git
|
||||
revision: 8d7c3ce14133760e748a0e34b99dfe6ec4d69153
|
||||
specs:
|
||||
jnunemaker-validatable (1.8.4)
|
||||
activesupport (>= 2.3.4)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
|
|
@ -241,12 +235,11 @@ DEPENDENCIES
|
|||
em-websocket
|
||||
factory_girl_rails
|
||||
haml
|
||||
jnunemaker-validatable (= 1.8.4)!
|
||||
json
|
||||
magent!
|
||||
mini_magick
|
||||
mocha
|
||||
mongo_mapper (= 0.8.4)!
|
||||
mongo_mapper!
|
||||
nifty-generators
|
||||
pubsubhubbub
|
||||
rails (= 3.0.0)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,13 @@
|
|||
# licensed under the Affero General Public License version 3. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
class PhotoAlbumValidator < ActiveModel::Validator
|
||||
def validate(document)
|
||||
unless document.album.person_id == document.person_id
|
||||
document.errors[:base] << "You post photos to that album"
|
||||
end
|
||||
end
|
||||
end
|
||||
class Photo < Post
|
||||
require 'carrierwave/orm/mongomapper'
|
||||
include MongoMapper::Document
|
||||
|
|
@ -22,7 +28,7 @@ class Photo < Post
|
|||
timestamps!
|
||||
|
||||
validates_presence_of :album
|
||||
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
|
||||
validates_with PhotoAlbumValidator
|
||||
|
||||
before_destroy :ensure_user_picture
|
||||
|
||||
|
|
@ -36,10 +42,6 @@ class Photo < Post
|
|||
photo
|
||||
end
|
||||
|
||||
def validate_album_person
|
||||
album.person_id == person_id
|
||||
end
|
||||
|
||||
def remote_photo
|
||||
image.url.nil? ? (remote_photo_path + '/' + remote_photo_name) : image.url
|
||||
end
|
||||
|
|
@ -70,3 +72,5 @@ class Photo < Post
|
|||
{:thumb_url => url(:thumb_medium), :id => id, :album_id => album_id}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue