diff --git a/app/controllers/commissioners_controller.rb b/app/controllers/commissioners_controller.rb index a1204de2..b0c1b2a8 100644 --- a/app/controllers/commissioners_controller.rb +++ b/app/controllers/commissioners_controller.rb @@ -15,6 +15,7 @@ class CommissionersController < ApplicationController # GET /commissioners/new def new @commissioner = Commissioner.new + @employee = Employee.all.order('name asc') end # GET /commissioners/1/edit @@ -25,7 +26,7 @@ class CommissionersController < ApplicationController # POST /commissioners.json def create @commissioner = Commissioner.new(commissioner_params) - + @commissioner.created_by = current_user.id respond_to do |format| if @commissioner.save format.html { redirect_to @commissioner, notice: 'Commissioner was successfully created.' } @@ -69,6 +70,6 @@ class CommissionersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def commissioner_params - params.fetch(:commissioner, {}) + params.require(:commissioner).permit(:name,:emp_id,:created_by,:commission_type, :is_active) end end diff --git a/app/models/commissioner.rb b/app/models/commissioner.rb index 057a94d0..c6d4ab4c 100644 --- a/app/models/commissioner.rb +++ b/app/models/commissioner.rb @@ -1,2 +1,3 @@ class Commissioner < ApplicationRecord + has_many :employees end diff --git a/app/models/employee.rb b/app/models/employee.rb index 85aeaec1..a6b52f21 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,6 +1,6 @@ class Employee < ApplicationRecord has_secure_password - + belongs_to :commissioner has_many :shit_sales validates_presence_of :name, :role validates_presence_of :password, :on => [:create] diff --git a/app/views/commissioners/_form.html.erb b/app/views/commissioners/_form.html.erb index 0ad6098b..6768b139 100644 --- a/app/views/commissioners/_form.html.erb +++ b/app/views/commissioners/_form.html.erb @@ -2,6 +2,10 @@ <%= f.error_notification %>
<%= notice %>
+| Name | +Employee Name | +Commission type | +Active | +Created By | |||||
|---|---|---|---|---|---|---|---|---|---|
| <%= link_to 'Show', commissioner %> | +<%= commissioner.name %> | ++ <% if Employee.exists? %> + <% employee = Employee.where('emp_id=?',commissioner.emp_id) %> + <%= employee[0].name %> + <% end %> + + | +<%= commissioner.commission_type %> | +<%= commissioner.is_active %> | +<%= current_user.name %> | +<%= link_to 'Show', commissioner_path(commissioner) %> | <%= link_to 'Edit', edit_commissioner_path(commissioner) %> | -<%= link_to 'Destroy', commissioner, method: :delete, data: { confirm: 'Are you sure?' } %> | +<%= link_to 'Destroy', commissioner_path(commissioner), method: :delete, data: { confirm: 'Are you sure?' } %> |
<%= notice %>
+| Name | <%= @commissioner.name %> |
| Employee Name | ++ <% if Employee.exists? %> + <% employee = Employee.where('emp_id=?',@commissioner.emp_id) %> + <%= employee[0].name %> + <% end %> + + |
| Commission Type | <%= @commissioner.commission_type %> |
| Active | <%= @commissioner.is_active %> |
| Created By | <%= current_user.name %> |
| <%= link_to 'Edit', edit_commissioner_path(@commissioner) %> | <%= link_to 'Destroy', commissioner_path(@commissioner), method: :delete, data: { confirm: 'Are you sure?' } %> |