New objects are now created through association
Added Sources to sidebar
This commit is contained in:
parent
ce9f011694
commit
c96cea5ca6
@ -6,14 +6,15 @@ class IngredientsController < ApplicationController
|
|||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ingredient = Ingredient.new(project: @project)
|
@ingredient = @project.ingredients.new
|
||||||
# passing attr for after_initialize
|
# passing attr for after_initialize
|
||||||
@ingredient.nutrients.new(ingredient: @ingredient)
|
@ingredient.nutrients.new(ingredient: @ingredient)
|
||||||
@ingredients = @project.ingredients.includes(:ref_unit)
|
@ingredients = @project.ingredients.includes(:ref_unit)
|
||||||
|
@ingredients << @ingredient
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@ingredient = Ingredient.new(ingredient_params.update(project: @project))
|
@ingredient = @project.ingredients.new(ingredient_params)
|
||||||
if @ingredient.save
|
if @ingredient.save
|
||||||
flash[:notice] = 'Created new ingredient'
|
flash[:notice] = 'Created new ingredient'
|
||||||
redirect_to project_ingredients_url(@project)
|
redirect_to project_ingredients_url(@project)
|
||||||
|
@ -4,12 +4,12 @@ class QuantitiesController < ApplicationController
|
|||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@quantity = Quantity.new
|
@quantity = @project.quantities.new
|
||||||
@quantities = @project.quantities
|
@quantities = @project.quantities
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@quantity = Quantity.new(quantity_params.update(project: @project))
|
@quantity = @project.quantities.new(quantity_params)
|
||||||
if @quantity.save
|
if @quantity.save
|
||||||
flash[:notice] = 'Created new quantity'
|
flash[:notice] = 'Created new quantity'
|
||||||
redirect_to project_quantities_url(@project)
|
redirect_to project_quantities_url(@project)
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
class SourcesController < ApplicationController
|
class SourcesController < ApplicationController
|
||||||
|
before_action :find_project_by_project_id, only: [:index, :create]
|
||||||
|
before_action :find_source, only: [:destroy]
|
||||||
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@source = @project.sources.new
|
||||||
|
@sources = @project.sources
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -4,12 +4,12 @@ class UnitsController < ApplicationController
|
|||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@unit = Unit.new
|
@unit = @project.units.new
|
||||||
@units = @project.units
|
@units = @project.units
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@unit = Unit.new(unit_params.update(project: @project))
|
@unit = @project.units.new(unit_params)
|
||||||
if @unit.save
|
if @unit.save
|
||||||
flash[:notice] = 'Created new unit'
|
flash[:notice] = 'Created new unit'
|
||||||
redirect_to project_units_url(@project)
|
redirect_to project_units_url(@project)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<h3><%= t ".heading_common" %></h3>
|
<h3><%= t ".heading_common" %></h3>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><%= link_to t(".link_sources"), project_sources_path(@project) %></li>
|
||||||
<li><%= link_to t(".link_quantities"), project_quantities_path(@project) %></li>
|
<li><%= link_to t(".link_quantities"), project_quantities_path(@project) %></li>
|
||||||
<li><%= link_to t(".link_units"), project_units_path(@project) %></li>
|
<li><%= link_to t(".link_units"), project_units_path(@project) %></li>
|
||||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<div class="box tabular">
|
<div class="box tabular">
|
||||||
<p><%= f.text_field :name, size: 40, required: true %></p>
|
<p><%= f.text_field :name, size: 40, required: true %></p>
|
||||||
<p>
|
<p>
|
||||||
<%= f.number_field :ref_amount, size: 8, required: true, min: 0 %>
|
<%= f.number_field :ref_amount, size: 8, required: true, min: 0, label: :field_reference %>
|
||||||
<%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
|
<%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
|
||||||
</p>
|
</p>
|
||||||
<p><%= f.select :group, group_options, required: true %></p>
|
<p><%= f.select :group, group_options, required: true %></p>
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%= t ".heading" %></h2>
|
<h2><%= t ".heading" %></h2>
|
||||||
<% if @ingredients.any? %>
|
<% if @ingredients.many? %>
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -59,6 +59,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @ingredients.each do |i| %>
|
<% @ingredients.each do |i| %>
|
||||||
|
<% next if i.new_record? %>
|
||||||
<tr id="ingredient-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>">
|
<tr id="ingredient-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>">
|
||||||
<td class="name"><%= i.name %></td>
|
<td class="name"><%= i.name %></td>
|
||||||
<td class="reference"><%= i.ref_amount %> [<%= i.ref_unit.shortname %>]</td>
|
<td class="reference"><%= i.ref_amount %> [<%= i.ref_unit.shortname %>]</td>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%= t ".heading" %></h2>
|
<h2><%= t ".heading" %></h2>
|
||||||
<% if @quantities.any? %>
|
<% if @quantities.many? %>
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -35,6 +35,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% Quantity.each_with_level(@quantities) do |q, level| %>
|
<% Quantity.each_with_level(@quantities) do |q, level| %>
|
||||||
|
<% next if q.new_record? %>
|
||||||
<tr id="quantity-<%= q.id %>"
|
<tr id="quantity-<%= q.id %>"
|
||||||
class="quantity <%= "project idnt idnt-#{level}" if level > 0 %>">
|
class="quantity <%= "project idnt idnt-#{level}" if level > 0 %>">
|
||||||
<td class="name"><span><%= q.name %></span></td>
|
<td class="name"><span><%= q.name %></span></td>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%= t ".heading" %></h2>
|
<h2><%= t ".heading" %></h2>
|
||||||
<% if @units.any? %>
|
<% if @units.many? %>
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -34,6 +34,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @units.each do |u| %>
|
<% @units.each do |u| %>
|
||||||
|
<% next if u.new_record? %>
|
||||||
<tr id="unit-<%= u.id %>" class="unit">
|
<tr id="unit-<%= u.id %>" class="unit">
|
||||||
<td class="shortname"><%= u.shortname %></td>
|
<td class="shortname"><%= u.shortname %></td>
|
||||||
<td class="unitname"><%= u.name %></td>
|
<td class="unitname"><%= u.name %></td>
|
||||||
|
@ -29,6 +29,7 @@ en:
|
|||||||
heading_common: 'Common'
|
heading_common: 'Common'
|
||||||
link_summary: 'Summary'
|
link_summary: 'Summary'
|
||||||
link_ingredients: 'Ingredients'
|
link_ingredients: 'Ingredients'
|
||||||
|
link_sources: 'Data sources'
|
||||||
link_quantities: 'Quantities'
|
link_quantities: 'Quantities'
|
||||||
link_units: 'Units'
|
link_units: 'Units'
|
||||||
link_defaults: 'Load defaults'
|
link_defaults: 'Load defaults'
|
||||||
|
Reference in New Issue
Block a user