diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index c401f29..39609d7 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -6,7 +6,7 @@ class QuantitiesController < ApplicationController def index @quantity = @project.quantities.new - @quantity.domain = Quantity.domains[session[:q_filters][:domain]] + @quantity.domain = Quantity.domains[session[:q_filters][:domain]] || @quantity.domain prepare_quantities end diff --git a/app/helpers/quantities_helper.rb b/app/helpers/quantities_helper.rb index 918e2e0..cee9a01 100644 --- a/app/helpers/quantities_helper.rb +++ b/app/helpers/quantities_helper.rb @@ -11,9 +11,8 @@ module QuantitiesHelper end def parent_options(domain) - options = nested_set_options(@quantities.send(domain), @quantity) do |i| + options = nested_set_options(@project.quantities.send(domain), @quantity) do |i| raw("#{' ' * i.level}#{i.name}") end - options.unshift([t('.null_parent'), nil]) end end diff --git a/app/models/quantity.rb b/app/models/quantity.rb index 2124ae4..cfdec64 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -19,6 +19,7 @@ class Quantity < ActiveRecord::Base after_initialize do if new_record? + self.domain ||= :diet self.primary = false if self.primary.nil? end end diff --git a/app/views/quantities/_form.html.erb b/app/views/quantities/_form.html.erb index 6a2c54c..3ce05ce 100644 --- a/app/views/quantities/_form.html.erb +++ b/app/views/quantities/_form.html.erb @@ -1,11 +1,12 @@ <%= error_messages_for @quantity %>
<%= f.select :domain, domain_options, required: true %>
+<%= f.select :domain, domain_options, {required: true} %>
<% Quantity.domains.each_key do |d| %> - diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index 18448df..3069093 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -14,10 +14,10 @@ <%= labelled_form_for @quantity, :url => project_quantities_path(@project), - :html => {:id => 'quantity-form'} do |f| %> + :html => {:id => 'quantity-add-form'} do |f| %> <%= render :partial => 'quantities/form', :locals => { :f => f } %> <%= submit_tag l(:button_create) %> - <%= link_to l(:button_cancel), "#", :onclick => '$("#add-quantity").hide()' %> + <%= link_to l(:button_cancel), "#", onclick: '$("#add-quantity").hide(); return false;' %> <% end %>