Skip to content

Instantly share code, notes, and snippets.

@klappradla
Created August 6, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klappradla/80eeda7538fd5a924ef83817156b8ffe to your computer and use it in GitHub Desktop.
Save klappradla/80eeda7538fd5a924ef83817156b8ffe to your computer and use it in GitHub Desktop.
Single file rails app to illustrate acceptance only validations
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails"
gem "pg"
gem "pry"
end
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "validation_example")
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
t.timestamps
end
end
class User < ActiveRecord::Base
validates_acceptance_of :terms_of_service
end
binding.pry
@klappradla
Copy link
Author

To run this:

createdb validation_example # assuming you have postgres installed and running

ruby validation_example.rb # to get into an interactive pry session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment