diff --git a/app/models/goal.rb b/app/models/goal.rb index 5af6f54..4e8730b 100644 --- a/app/models/goal.rb +++ b/app/models/goal.rb @@ -7,9 +7,12 @@ class Goal < ActiveRecord::Base has_many :quantities, -> { order "lft" }, through: :target_exposures validates :target_exposures, presence: true + validates :is_binding, uniqueness: {scope: :project_id}, if: :is_binding? validates :name, presence: true, uniqueness: {scope: :project_id} - def is_binding? - self == project.goals.binding + after_initialize do + if new_record? + self.is_binding = false if self.is_binding.nil? + end end end diff --git a/app/views/targets/_form.html.erb b/app/views/targets/_form.html.erb index dc6b237..645706e 100644 --- a/app/views/targets/_form.html.erb +++ b/app/views/targets/_form.html.erb @@ -3,7 +3,7 @@ <% @targets.group_by(&:goal).each do |goal, targets| %>
<%= render partial: 'goals/show_form', locals: {goal: goal} %>
<%#= t '.effective_from' %><%= f.date_field :effective_from, disabled: !goal.is_binding? %>
diff --git a/app/views/targets/_index.html.erb b/app/views/targets/_index.html.erb index 7edd1fb..5c667de 100644 --- a/app/views/targets/_index.html.erb +++ b/app/views/targets/_index.html.erb @@ -9,33 +9,35 @@ <%= error_messages_for *formulas %><%= l(:field_effective_from) %> | +<%= l(:field_effective_from) %> | <% end %> <% row.each do |q, span| %> -0 %> <%= "rowspan=#{-span}" if span && span < 0 %> style="width: <%= (span && span > 0 ? span : 1) * 100/total_width %>%;" title="<%= q.description %>"> <%= q.name if span %> - | + <% end %> <% if i == 0 %> -<%= l(:field_action) %> | +<%= l(:field_action) %> | <% end %>
---|---|---|---|---|