Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
## sample from http://api.rubyonrails.org/classes/ActiveResource/Validations.html class Person < ActiveResource::Base self.site = "http://www.fake.com/" # doesn't matter because an invalid object won't even attempt to save def validate errors.add_on_empty %w( first_name last_name ) errors.add("phone_number", "has invalid format") unless phone_number =~ /[0-9]*/ end end ## Running the example code person = Person.new("first_name" => "Jim", "phone_number" => "I will not tell you.") #<Person:0x4b94c @attributes={"phone_number"=>"I will not tell you.", "first_name"=>"Jim"}, @prefix_options={}> p.save # => ActiveResource::MethodNotAllowed: Failed with 405 Method not allowed ## A method with undefined variables # You can ever but in broken code into the validate method. It's never called class Person < ActiveResource::Base self.site = "http://www.fake.com/" # doesn't matter because an invalid object won't even attempt to save def validate a b c end end ## Running the code person = Person.new("first_name" => "Jim", "phone_number" => "I will not tell you.") #=> <Person:0x4b94c @attributes={"phone_number"=>"I will not tell you.", "first_name"=>"Jim"}, @prefix_options={}> p.save # => ActiveResource::MethodNotAllowed: Failed with 405 Method not allowed ## You can even manually add in errors and the object will still attempt a remote save person.errors.add(:base, "I am invalid and won't even try bother the server") # => ["I am invalid and won't even try to bother the server"] p.valid? # => false p.save # => ActiveResource::MethodNotAllowed: Failed with 405 Method not allowed
This paste will be private.
From the Design Piracy series on my blog: