Permalink
Browse files

Employee and Reimbursement scaffolds

  • Loading branch information...
danielfone committed Oct 19, 2013
1 parent fd4055e commit 2c3fe4770203d66e25c41482deb78c19491062c8
@@ -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 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 Employees controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Reimbursements controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,69 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a {
+ color: #000;
+ &:visited {
+ color: #666;
+ }
+ &:hover {
+ color: #fff;
+ background-color: #000;
+ }
+}
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px;
+ }
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+ }
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
+}
@@ -0,0 +1,74 @@
+class EmployeesController < ApplicationController
+ before_action :set_employee, only: [:show, :edit, :update, :destroy]
+
+ # GET /employees
+ # GET /employees.json
+ def index
+ @employees = Employee.all
+ end
+
+ # GET /employees/1
+ # GET /employees/1.json
+ def show
+ end
+
+ # GET /employees/new
+ def new
+ @employee = Employee.new
+ end
+
+ # GET /employees/1/edit
+ def edit
+ end
+
+ # POST /employees
+ # POST /employees.json
+ def create
+ @employee = Employee.new(employee_params)
+
+ respond_to do |format|
+ if @employee.save
+ format.html { redirect_to @employee, notice: 'Employee was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @employee }
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @employee.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /employees/1
+ # PATCH/PUT /employees/1.json
+ def update
+ respond_to do |format|
+ if @employee.update(employee_params)
+ format.html { redirect_to @employee, notice: 'Employee was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @employee.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /employees/1
+ # DELETE /employees/1.json
+ def destroy
+ @employee.destroy
+ respond_to do |format|
+ format.html { redirect_to employees_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_employee
+ @employee = Employee.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def employee_params
+ params.require(:employee).permit(:name)
+ end
+end
@@ -0,0 +1,74 @@
+class ReimbursementsController < ApplicationController
+ before_action :set_reimbursement, only: [:show, :edit, :update, :destroy]
+
+ # GET /reimbursements
+ # GET /reimbursements.json
+ def index
+ @reimbursements = Reimbursement.all
+ end
+
+ # GET /reimbursements/1
+ # GET /reimbursements/1.json
+ def show
+ end
+
+ # GET /reimbursements/new
+ def new
+ @reimbursement = Reimbursement.new
+ end
+
+ # GET /reimbursements/1/edit
+ def edit
+ end
+
+ # POST /reimbursements
+ # POST /reimbursements.json
+ def create
+ @reimbursement = Reimbursement.new(reimbursement_params)
+
+ respond_to do |format|
+ if @reimbursement.save
+ format.html { redirect_to @reimbursement, notice: 'Reimbursement was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @reimbursement }
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @reimbursement.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /reimbursements/1
+ # PATCH/PUT /reimbursements/1.json
+ def update
+ respond_to do |format|
+ if @reimbursement.update(reimbursement_params)
+ format.html { redirect_to @reimbursement, notice: 'Reimbursement was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @reimbursement.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /reimbursements/1
+ # DELETE /reimbursements/1.json
+ def destroy
+ @reimbursement.destroy
+ respond_to do |format|
+ format.html { redirect_to reimbursements_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_reimbursement
+ @reimbursement = Reimbursement.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def reimbursement_params
+ params.require(:reimbursement).permit(:reference, :payee_id, :comments, :data)
+ end
+end
@@ -0,0 +1,2 @@
+module EmployeesHelper
+end
@@ -0,0 +1,2 @@
+module ReimbursementsHelper
+end
View
@@ -0,0 +1,2 @@
+class Employee < ActiveRecord::Base
+end
@@ -0,0 +1,3 @@
+class Reimbursement < ActiveRecord::Base
+ belongs_to :payee
+end
@@ -0,0 +1,21 @@
+<%= form_for(@employee) do |f| %>
+ <% if @employee.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@employee.errors.count, "error") %> prohibited this employee from being saved:</h2>
+
+ <ul>
+ <% @employee.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br>
+ <%= f.text_field :name %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing employee</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @employee %> |
+<%= link_to 'Back', employees_path %>
@@ -0,0 +1,27 @@
+<h1>Listing employees</h1>
+
+<table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @employees.each do |employee| %>
+ <tr>
+ <td><%= employee.name %></td>
+ <td><%= link_to 'Show', employee %></td>
+ <td><%= link_to 'Edit', edit_employee_path(employee) %></td>
+ <td><%= link_to 'Destroy', employee, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Employee', new_employee_path %>
@@ -0,0 +1,4 @@
+json.array!(@employees) do |employee|
+ json.extract! employee, :name
+ json.url employee_url(employee, format: :json)
+end
@@ -0,0 +1,5 @@
+<h1>New employee</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', employees_path %>
@@ -0,0 +1,9 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>Name:</strong>
+ <%= @employee.name %>
+</p>
+
+<%= link_to 'Edit', edit_employee_path(@employee) %> |
+<%= link_to 'Back', employees_path %>
@@ -0,0 +1 @@
+json.extract! @employee, :name, :created_at, :updated_at
@@ -0,0 +1,33 @@
+<%= form_for(@reimbursement) do |f| %>
+ <% if @reimbursement.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@reimbursement.errors.count, "error") %> prohibited this reimbursement from being saved:</h2>
+
+ <ul>
+ <% @reimbursement.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :reference %><br>
+ <%= f.text_field :reference %>
+ </div>
+ <div class="field">
+ <%= f.label :payee %><br>
+ <%= f.text_field :payee %>
+ </div>
+ <div class="field">
+ <%= f.label :comments %><br>
+ <%= f.text_area :comments %>
+ </div>
+ <div class="field">
+ <%= f.label :data %><br>
+ <%= f.text_area :data %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing reimbursement</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @reimbursement %> |
+<%= link_to 'Back', reimbursements_path %>
Oops, something went wrong.

0 comments on commit 2c3fe47

Please sign in to comment.