app port from old version
This commit is contained in:
@ -2,4 +2,6 @@ class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
respond_to :html, :json
|
||||
end
|
||||
|
@ -1,2 +1,6 @@
|
||||
class ChildrenController < ApplicationController
|
||||
def index
|
||||
@children = Child.all.order(:last_name, :first_name)
|
||||
respond_with @children
|
||||
end
|
||||
end
|
||||
|
@ -1,2 +1,6 @@
|
||||
class StaffController < ApplicationController
|
||||
def index
|
||||
@staff = Person.staff
|
||||
respond_with @staff
|
||||
end
|
||||
end
|
||||
|
@ -1,2 +1,6 @@
|
||||
class UsersController < ApplicationController
|
||||
def index
|
||||
@users = Person.admins
|
||||
respond_with @users
|
||||
end
|
||||
end
|
||||
|
11
app/models/child.rb
Normal file
11
app/models/child.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class Child < ActiveRecord::Base
|
||||
has_many :parenthoods
|
||||
has_many :parents, through: :parenthoods, source: :person
|
||||
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
4
app/models/parenthood.rb
Normal file
4
app/models/parenthood.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Parenthood < ActiveRecord::Base
|
||||
belongs_to :person
|
||||
belongs_to :child
|
||||
end
|
25
app/models/person.rb
Normal file
25
app/models/person.rb
Normal file
@ -0,0 +1,25 @@
|
||||
class Person < ActiveRecord::Base
|
||||
has_many :parenthoods
|
||||
has_many :children, through: :parenthoods
|
||||
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
|
||||
scope :with_name, lambda { |name|
|
||||
where("concat(first_name, ' ', last_name) RLIKE ?", name)
|
||||
}
|
||||
|
||||
scope :just_parents, lambda {
|
||||
joins(:children)
|
||||
.order(:first_name)
|
||||
.uniq
|
||||
}
|
||||
|
||||
scope :staff, -> { where(staff: true) }
|
||||
|
||||
scope :admins, -> { where(admin: true) }
|
||||
|
||||
def name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
8
app/views/children/index.haml
Normal file
8
app/views/children/index.haml
Normal file
@ -0,0 +1,8 @@
|
||||
%h1 Children
|
||||
|
||||
- @children.each do |child|
|
||||
%ul
|
||||
%li= child.name
|
||||
%ul
|
||||
- child.parents.each do |parent|
|
||||
%li #{parent.name}: #{number_to_phone parent.phone}
|
11
app/views/parents/index.haml
Normal file
11
app/views/parents/index.haml
Normal file
@ -0,0 +1,11 @@
|
||||
%h1 Parents
|
||||
|
||||
- @parents.each do |parent|
|
||||
%ul
|
||||
%li= parent.name
|
||||
%li= number_to_phone parent.phone
|
||||
%li= mail_to parent.email
|
||||
%li Children:
|
||||
%ul
|
||||
- parent.children.each do |child|
|
||||
%li= child.name
|
4
app/views/staff/index.haml
Normal file
4
app/views/staff/index.haml
Normal file
@ -0,0 +1,4 @@
|
||||
%h1 Staff
|
||||
%ul
|
||||
- @staff.each do |staff|
|
||||
%li= staff.name
|
5
app/views/users/index.haml
Normal file
5
app/views/users/index.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%h1 Users
|
||||
|
||||
%ul
|
||||
- @users.each do |user|
|
||||
%li= user.name
|
Reference in New Issue
Block a user