diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 0dde53d..efcd0b2 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -7,7 +7,7 @@ class IngredientsController < ApplicationController def index @ingredient = @project.ingredients.new - # passing attr for after_initialize + # passing attr for Nutrient after_initialize @ingredient.nutrients.new(ingredient: @ingredient) @ingredients = @project.ingredients.includes(:ref_unit) @ingredients << @ingredient diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index c53dd97..a1cf616 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -39,7 +39,7 @@ class SourcesController < ApplicationController # :find_* methods are called before :authorize, # @project is required for :authorize to succeed def find_source - @unit = Source.find(params[:id]) + @source = Source.find(params[:id]) @project = @source.project rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/models/source.rb b/app/models/source.rb index 12221de..01160d9 100644 --- a/app/models/source.rb +++ b/app/models/source.rb @@ -1,2 +1,5 @@ class Source < ActiveRecord::Base + belongs_to :project, required: false + + validates :name, presence: true, uniqueness: {scope: :project_id} end diff --git a/app/views/sources/_form.html.erb b/app/views/sources/_form.html.erb new file mode 100644 index 0000000..0da28d8 --- /dev/null +++ b/app/views/sources/_form.html.erb @@ -0,0 +1,6 @@ +<%= error_messages_for @source %> + +
<%= f.text_field :name, required: true, size: 20 %>
+<%= f.text_area :description, rows: 3, cols: 60 %>
+<%= l(:field_name) %> | +<%= l(:field_description) %> | +<%= l(:field_action) %> | +
---|---|---|
<%= s.name %> | +<%= s.description %> | +<%= delete_link source_path(s), data: {} %> | +
<%= l(:label_no_data) %>
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c167a66..c8f533d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -54,6 +54,10 @@ en: groups: other: 'other' meat: 'meat' + sources: + index: + heading: 'Data sources' + heading_new_source: 'New source' quantities: index: heading: 'Quantities' diff --git a/lib/body_tracking/project_patch.rb b/lib/body_tracking/project_patch.rb index debed83..ef00929 100644 --- a/lib/body_tracking/project_patch.rb +++ b/lib/body_tracking/project_patch.rb @@ -3,6 +3,7 @@ module BodyTracking Project.class_eval do has_many :ingredients, -> { order "name" }, dependent: :destroy + has_many :sources, dependent: :destroy has_many :quantities, -> { order "lft" }, dependent: :destroy has_many :units, dependent: :destroy end