Permalink
Browse files

Select Payee from Employees

  • Loading branch information...
danielfone committed Oct 19, 2013
1 parent f4cd029 commit 5a512719d522f4cf063632dfd1b6a18875db67aa
@@ -1,3 +1,6 @@
class Reimbursement < ActiveRecord::Base
- belongs_to :payee
+ belongs_to :payee, class_name: 'Employee'

This comment has been minimized.

Show comment
Hide comment
@danielfone

danielfone Oct 19, 2013

Owner

By default, Rails would look for a model called 'Payee', we can override that with the :class_name option.

@danielfone

danielfone Oct 19, 2013

Owner

By default, Rails would look for a model called 'Payee', we can override that with the :class_name option.

+
+ validates :payee_id, presence: true
+
end
@@ -1,3 +1,5 @@
+<%= render 'shared/errors', object: @reimbursement %>
+
<%= form_for @reimbursement, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :reference, :class => 'control-label' %>
@@ -8,7 +10,7 @@
<div class="control-group">
<%= f.label :payee_id, :class => 'control-label' %>
<div class="controls">
- <%= f.text_field :payee_id, :class => 'text_field' %>
+ <%= f.collection_select :payee_id, Employee.all, :id, :name, prompt: 'Select employee...' %>
</div>
</div>
<div class="control-group">
@@ -19,7 +19,7 @@
<tr>
<td><%= link_to reimbursement.id, reimbursement_path(reimbursement) %></td>
<td><%= reimbursement.reference %></td>
- <td><%= reimbursement.payee_id %></td>
+ <td><%= reimbursement.payee.name %></td>

This comment has been minimized.

Show comment
Hide comment
@danielfone

danielfone Oct 19, 2013

Owner

This is poor form. We should define a method called payee_name on the reimbursement model (or use a delegator). This code will raise an exception if the reimbursement doesn't have a payee.

But we are prototyping so we don't care.

@danielfone

danielfone Oct 19, 2013

Owner

This is poor form. We should define a method called payee_name on the reimbursement model (or use a delegator). This code will raise an exception if the reimbursement doesn't have a payee.

But we are prototyping so we don't care.

<td><%= reimbursement.comments %></td>
<td><%= reimbursement.data %></td>
<td><%=l reimbursement.created_at %></td>
@@ -7,7 +7,7 @@
<dt><strong><%= model_class.human_attribute_name(:reference) %>:</strong></dt>
<dd><%= @reimbursement.reference %></dd>
<dt><strong><%= model_class.human_attribute_name(:payee_id) %>:</strong></dt>
- <dd><%= @reimbursement.payee_id %></dd>
+ <dd><%= @reimbursement.payee.name %></dd>

This comment has been minimized.

Show comment
Hide comment
@danielfone

danielfone Oct 19, 2013

Owner

Same here:

This is poor form. We should define a method called payee_name on the reimbursement model (or use a delegator). This code will raise an exception if the reimbursement doesn't have a payee.

But we are prototyping so we don't care.

@danielfone

danielfone Oct 19, 2013

Owner

Same here:

This is poor form. We should define a method called payee_name on the reimbursement model (or use a delegator). This code will raise an exception if the reimbursement doesn't have a payee.

But we are prototyping so we don't care.

<dt><strong><%= model_class.human_attribute_name(:comments) %>:</strong></dt>
<dd><%= @reimbursement.comments %></dd>
<dt><strong><%= model_class.human_attribute_name(:data) %>:</strong></dt>

0 comments on commit 5a51271

Please sign in to comment.