Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

activerecord - Validation that excludes itself on update action if fields have not changed -


i have table called rents hold start , end date. have created validation no new rents cant overlap existing rents start , end dates.

the thing is, when click on rent update , if don't change fields , click update. trys validate on , overlapping existing record. ( existing record referring itself.)

the thing im trying is, how can have validation exclude itself. how validation looks like.

def should_not_overlap_rental_periods   errors.add(:start_date, "can't overlap other rental periods") if self.rents.where("end_date <= ? , start_date >= ?", self.end_date.strftime("%y-%m-%d"), self.start_date.strftime("%y-%m-%d")).count > 0 unless self.rents.blank?  end 

you need check on activemodel's dirty checking module. can check on attributes if have changed , branch logic accordingly.

http://railsapi.com/doc/rails-v3.0.1/classes/activemodel/dirty.html


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -