Skip to content

Commit

Permalink
Moved embedded ruby code for displaying data values into method
Browse files Browse the repository at this point in the history
  • Loading branch information
ottopchen committed Sep 14, 2016
1 parent fc10dee commit 4966143
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/models/data_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ def previous_data_value
def formula
self.input_formula.blank? ? data_type.formula : self.input_formula
end

def get_value
self.value ? self.value : self.formula_value
end
end
9 changes: 2 additions & 7 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@
<% data_type.data_values.includes(:project_year).sort_by_year.each do |data_value| %>
<% if @project.project_years.find_by_id(data_value.project_year.id) %>
<td class="data-value" data-id=<%= data_value.id %> contentEditable="true" data-input-formula="<%= data_value.input_formula %>" data-type="<%= data_value.data_type.input_type%>" onclick="showFormula(this, '<%= name %>');">
<% if data_value.value %>
<% @val = data_value.value %>
<% else %>
<% @val = data_value.formula_value %>
<% end %>
<% if data_value.data_type.currency? %>
<%= number_to_currency(@val) %></td>
<%= number_to_currency(data_value.get_value) %></td>
<% else %>
<%= @val %></td>
<%= data_value.get_value %></td>
<% end %>
<% end %>
<% end %>
Expand Down

0 comments on commit 4966143

Please sign in to comment.