Permalink
Browse files

Added People/Person for guests and other addressbookentries. User is …

…inheriting from Person
  • Loading branch information...
1 parent b2b9e6e commit efd4d3e38fdcf77c2645afc6d2290b31df036014 Ayonix committed Apr 11, 2013
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
@@ -0,0 +1,3 @@
+// Place all the styles related to the People controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,54 @@
+class PeopleController < ApplicationController
+ before_action :set_person, only: [:show, :edit, :update]
+ before_action :signed_in_user
+
+ # GET /users
+ def index
+ @people = Person.all
+ end
+
+ # GET /users/1
+ def show
+ end
+
+ # GET /users/new
+ def new
+ @person = Person.new
+ end
+
+ # GET /users/1/edit
+ def edit
+ end
+
+ # POST /users
+ def create
+ @person = Person.new(person_params)
+
+ if @person.save
+ redirect_to @person, notice: 'Person was successfully created.'
+ else
+ render action: 'new'
+ end
+ end
+
+ # PATCH/PUT /users/1
+ def update
+ if @person.update(person_params)
+ login @person
+ redirect_to @person, notice: 'User was successfully updated.'
+ else
+ render action: 'edit'
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_person
+ @person = Person.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def person_params
+ params.require(:person).permit(:firstname, :lastname, :street, :zip, :city, :email, :phone, :birthday, :misc)
+ end
+end
@@ -0,0 +1,2 @@
+module PeopleHelper
+end
View
@@ -0,0 +1,23 @@
+# == Schema Information
+#
+# Table name: people
+#
+# id :integer not null, primary key
+# firstname :string(255)
+# lastname :string(255)
+# street :string(255)
+# zip :string(255)
+# city :string(255)
+# email :string(255)
+# phone :string(255)
+# birthday :date
+# misc :text
+# loginname :string(255)
+# remember_token :string(255)
+# type :string(255)
+# created_at :datetime
+# updated_at :datetime
+#
+
+class Person < ActiveRecord::Base
+end
View
@@ -1,9 +1,8 @@
# == Schema Information
#
-# Table name: users
+# Table name: people
#
# id :integer not null, primary key
-# loginname :string(255)
# firstname :string(255)
# lastname :string(255)
# street :string(255)
@@ -13,12 +12,15 @@
# phone :string(255)
# birthday :date
# misc :text
+# loginname :string(255)
# remember_token :string(255)
+# type :string(255)
# created_at :datetime
# updated_at :datetime
+#
require 'net/ldap'
-class User < ActiveRecord::Base
+class User < Person
has_many :tabs
before_save :create_remember_token
@@ -12,7 +12,7 @@
<li class="active"><a href="#">Aktiv</a></li>
<li><%= link_to 'Protokolle', minutes_path %></li>
<% if signed_in? %>
- <li><%= link_to 'Adressbuch', users_path %></li>
+ <li><%= link_to 'Adressbuch', people_path %></li>
<li class="has-dropdown">
<% if has_group('kuehlschrank') %>
<a href="#">Kühlschrank</a>
@@ -0,0 +1,36 @@
+<%= form_for(@person) do |f| %>
+ <% if @person.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@person.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @person.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <%= f.label :firstname %>
+ <%= f.text_field :firstname %><br />
+ <%= f.label :lastname %>
+ <%= f.text_field :lastname %><br />
+ <%= f.label :street %>
+ <%= f.text_field :street %><br />
+ <%= f.label :zip %>
+ <%= f.text_field :zip %><br />
+ <%= f.label :city %>
+ <%= f.text_field :city %><br />
+ <%= f.label :email %>
+ <%= f.text_field :email %><br />
+ <%= f.label :phone %>
+ <%= f.text_field :phone %><br />
+ <%= f.label :birthday %>
+ <%= f.date_field :birthday, :start_year => 1950, :end_year => Date.today.year %><br />
+ <%= f.label :misc %>
+ <%= f.text_area :misc %><br />
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,11 @@
+<tr>
+ <td><%= person.firstname %></td>
+ <td><%= person.lastname %></td>
+ <td><%= person.street %></td>
+ <td><%= person.zip %></td>
+ <td><%= person.city %></td>
+ <td><%= person.email %></td>
+ <td><%= person.phone %></td>
+ <td><%= person.birthday %></td>
+ <td><%= person.misc %></td>
+</tr>
@@ -0,0 +1,6 @@
+<h1>Editing person</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @person %> |
+<%= link_to 'Back', persons_path %>
@@ -0,0 +1,39 @@
+<div class="actions">
+ <h1 style=""><%=t '.heading' %></h1>
+ <a href="<%= new_person_path %>" class="button small round secondary">
+ <span class="icon-plus"> Neuen Eintrag Anlegen</span>
+ </a>
+</div>
+
+<table>
+ <colgroup>
+ <col width="24%">
+ <col width="24%">
+ <col width="24%">
+ <col width="24%">
+ <col width="2%">
+ <col width="2%">
+ </colgroup>
+ <thead>
+ <tr>
+ <th><%=t Person.human_attribute_name :firstname %></th>
+ <th><%=t Person.human_attribute_name :lastname %></th>
+ <th><%=t Person.human_attribute_name :email %></th>
+ <th><%=t Person.human_attribute_name :phone %></th>
+ <th>Aktionen</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @people.each do |person| %>
+ <tr>
+ <td><%= person.firstname %></td>
+ <td><%= person.lastname %></td>
+ <td><%= person.email %></td>
+ <td><%= person.phone %></td>
+ <td class="center no-linebreak">
+ <a href="<%= person_path(person) %>"><span class="icon-info-circled">Details</span></a>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
@@ -0,0 +1,6 @@
+<p id="notice"><%= notice %></p>
+
+<%= render @person %>
+
+<br />
+<%= link_to 'Back', people_path %>
View
@@ -2,6 +2,7 @@
# resources :$deutschername, :as => "$englishname", :controller => "$englishname"
Fsintra::Application.routes.draw do
resources :benutzer, except: [:destroy], :as => 'users', :controller => 'users'
+ resources :personen, except: [:destroy], :as => 'people', :controller => 'people'
resources :rechnungen, :as => 'tabs', :controller => 'tabs' do
get 'offen' => 'tabs#unpaid', :on => :collection
put 'ist_bezahlt' => 'tabs#set_paid', :on => :member
@@ -0,0 +1,20 @@
+class CreatePeople < ActiveRecord::Migration
+ def change
+ create_table :people do |t|
+ t.string :firstname
+ t.string :lastname
+ t.string :street
+ t.string :zip
+ t.string :city
+ t.string :email
+ t.string :phone
+ t.date :birthday
+ t.text :misc
+ t.string :loginname
+ t.string :remember_token
+ t.string :type
+
+ t.timestamps
+ end
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20130410205254) do
+ActiveRecord::Schema.define(version: 20130411150027) do
create_table "beverage_tabs", force: true do |t|
t.integer "beverage_id"
@@ -65,6 +65,23 @@
t.integer "minute_id"
end
+ create_table "people", force: true do |t|
+ t.string "firstname"
+ t.string "lastname"
+ t.string "street"
+ t.string "zip"
+ t.string "city"
+ t.string "email"
+ t.string "phone"
+ t.date "birthday"
+ t.text "misc"
+ t.string "loginname"
+ t.string "remember_token"
+ t.string "type"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "tabs", force: true do |t|
t.integer "user_id"
t.datetime "created_at"
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PeopleControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,50 @@
+# == Schema Information
+#
+# Table name: people
+#
+# id :integer not null, primary key
+# firstname :string(255)
+# lastname :string(255)
+# street :string(255)
+# zip :string(255)
+# city :string(255)
+# email :string(255)
+# phone :string(255)
+# birthday :date
+# misc :text
+# loginname :string(255)
+# remember_token :string(255)
+# type :string(255)
+# created_at :datetime
+# updated_at :datetime
+#
+
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ firstname: MyString
+ lastname: MyString
+ street: MyString
+ zip: MyString
+ city: MyString
+ email: MyString
+ phone: MyString
+ birthday: 2013-04-11
+ misc: MyText
+ loginname: MyString
+ remember_token: MyString
+ type:
+
+two:
+ firstname: MyString
+ lastname: MyString
+ street: MyString
+ zip: MyString
+ city: MyString
+ email: MyString
+ phone: MyString
+ birthday: 2013-04-11
+ misc: MyText
+ loginname: MyString
+ remember_token: MyString
+ type:
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PeopleHelperTest < ActionView::TestCase
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PersonTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit efd4d3e

Please sign in to comment.