Created
July 15, 2011 12:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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