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