Created
July 23, 2008 19:15
-
-
Save chrisconley/1863 to your computer and use it in GitHub Desktop.
This file contains 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
## Routes | |
map.add_person '/add_person', :controller => 'people', :action => 'new_unclaimed_person' | |
map.add '/add', :controller => 'people', :action => 'create_unclaimed_person' | |
## People Controller | |
def new_unclaimed_person | |
@person = Person.new | |
end | |
def create_unclaimed_person | |
logout_keeping_session! | |
@person = Person.create(params[:person]) | |
@person.add! if @person && @person.valid? | |
success = @person && @person.valid? | |
if success && @person.errors.empty? | |
redirect_back_or_default('/') | |
flash[:notice] = "moo" | |
else | |
flash[:error] = "moo" | |
render :action => 'new_unclaimed_person' | |
end | |
end | |
## PersonObserver | |
#so we don't try to send an email to an unclaimed user | |
def after_create(person) | |
PersonMailer.deliver_signup_notification(person) if person.email | |
end | |
## stateful_roles.rb | |
# I think we can put this in the Person model so we don't have to muck with the plugin | |
#setting initial state to passive messes up creating a new real user. | |
acts_as_state_machine :initial => :passive | |
state :unclaimed | |
event :add do | |
transitions :from => :passive, :to => :unclaimed | |
end | |
# the state can be changed to pending when the user registers fresh or from claiming an existing user => [:passive, :unclaimed] | |
event :register do | |
transitions :from => [:passive, :unclaimed], :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) } | |
end | |
This file contains 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
<h1>Add Person</h1> | |
<%= debug @person %> | |
<%= error_messages_for :person %> | |
<% form_for :person, :url => add_path do |f| -%> | |
<p><label for="name">Name</label><br/> | |
<%= f.text_field :name %></p> | |
<p><label for="position">Position</label><br/> | |
<%= f.text_field :position %></p> | |
<!-- this was trying to hard set the state --!> | |
<%= f.hidden_field(:state, :value => "unclaimed") %> | |
<p><%= submit_tag 'Add' %></p> | |
<% end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment