Skip to content

Instantly share code, notes, and snippets.

@tatey
Created July 15, 2011 12:00
Show Gist options
  • Select an option

  • Save tatey/1084561 to your computer and use it in GitHub Desktop.

Select an option

Save tatey/1084561 to your computer and use it in GitHub Desktop.
Would be nice to be able to do this in Rails 2.3
class Citizen < ActiveRecord::Base
contextual :everyone do
validates_presence_of :last_name
validates_format_of :email, :with => /\w+/
end
contextual :admin do
validates_presence :first_name
end
end
class CitizensController < ApplicationController
def create
@citizen = Citizen.new params[:citizen]
if @citizen.save :context => :everyone
redirect_to @citizen
else
render :new
end
end
end
class Admin::CitizensController < AdminController
def create
@citizen = Citizen.new params[:citizen]
if @citizen.save :context => :admin
redirect_to @citizen
else
render :new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment