Created
February 25, 2010 18:29
-
-
Save francois/314862 to your computer and use it in GitHub Desktop.
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
<extend tag="form" for="Person"> | |
<old-form merge> | |
<field-list: fields="prefix, first_name, last_name, door_number, address1, address2, address3, city, postal_code, home_number, mobile_number, email, employees"> | |
<employees-view:> | |
<input-many> | |
<field-list fields="title, company, email, direct_number, extension"> | |
</field-list> | |
</input-many> | |
</employees-view:> | |
</field-list:> | |
</old-form> | |
</extend> | |
<extend tag="form" for="Company"> | |
<old-form merge> | |
<field-list: fields="name, door_number, address1, address2, address3, city, postal_code, main_number, fax_number, toll_free_number, other_number, email, url, employees"> | |
<employees-view:> | |
<input-many> | |
<field-list fields="title, person, email, direct_number, extension"> | |
</field-list> | |
</input-many> | |
</employees-view:> | |
</field-list:> | |
</old-form> | |
</extend> |
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 Company < ActiveRecord::Base | |
hobo_model # Don't put anything above this | |
has_many :employees, :accessible => true, :dependent => :destroy | |
has_many :people, :through => :employees | |
def create_permitted? | |
!acting_user.guest? | |
end | |
def update_permitted? | |
!acting_user.guest? | |
end | |
def destroy_permitted? | |
acting_user.administrator? | |
end | |
def view_permitted?(field) | |
true | |
end | |
end |
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 Employee < ActiveRecord::Base | |
hobo_model # Don't put anything above this | |
belongs_to :company | |
belongs_to :person | |
def create_permitted? | |
!acting_user.guest? | |
end | |
def update_permitted? | |
!acting_user.guest? | |
end | |
def destroy_permitted? | |
acting_user.administrator? | |
end | |
def view_permitted?(field) | |
true | |
end | |
end |
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 EmployeesController < ApplicationController | |
hobo_model_controller | |
auto_actions :all | |
end |
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 Event < ActiveRecord::Base | |
hobo_model # Don't put anything above this | |
belongs_to :addressee, :polymorphic => true | |
end |
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
bidule = User.find_by_email_address("bidule@teksol.info") | |
francois = User.find_by_email_address("francois@teksol.info") | |
person = Person.find(1381) | |
emp = person.employees.first | |
emp.nil? | |
#=> false | |
francois.administrator? | |
#=> true | |
bidule.administrator? | |
#=> false | |
emp.editable_by?(bidule) | |
=> true | |
emp.editable_by?(francois) | |
#=> true | |
emp.acting_user = bidule | |
emp.update_permitted? | |
#=> true | |
emp.acting_user = francois | |
emp.update_permitted? | |
#=> true |
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 Person < ActiveRecord::Base | |
hobo_model # Don't put anything above this | |
has_many :employees, :accessible => true, :dependent => :destroy | |
has_many :companies, :through => :employees | |
def create_permitted? | |
!acting_user.guest? | |
end | |
def update_permitted? | |
!acting_user.guest? | |
end | |
def destroy_permitted? | |
acting_user.administrator? | |
end | |
def view_permitted?(field) | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment