Fixed saving Meal exposures
According to: https://stackoverflow.com/questions/34328735/imageable-type-is-not-setting-for-polymorphic-associations and https://stackoverflow.com/questions/2494452/rails-polymorphic-association-with-multiple-associations-on-the-same-model
This commit is contained in:
parent
ab8ed92929
commit
c029ba59c2
@ -9,7 +9,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="width:100%"></td>
|
<td style="width:100%"></td>
|
||||||
<td><%= select_tag 'quantity_id',
|
<td><%= select_tag 'quantity_id',
|
||||||
toggle_exposure_options(@project.meal_exposures, :diet) %></td>
|
toggle_exposure_options(@project.meal_quantities, :diet) %></td>
|
||||||
<td><%= submit_tag l(:button_add) %></td>
|
<td><%= submit_tag l(:button_add) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
1
app/views/meals/toggle_exposure.js.erb
Normal file
1
app/views/meals/toggle_exposure.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
$('#meals').html('<%= j render partial: 'meals/index' %>');
|
@ -6,7 +6,8 @@ module BodyTracking::ProjectPatch
|
|||||||
|
|
||||||
has_many :foods, -> { order "name" }, dependent: :destroy,
|
has_many :foods, -> { order "name" }, dependent: :destroy,
|
||||||
extend: BodyTracking::ItemsWithQuantities
|
extend: BodyTracking::ItemsWithQuantities
|
||||||
has_many :nutrient_exposures, as: :view, dependent: :destroy,
|
has_many :nutrient_exposures, -> { where view_type: "Nutrient" }, dependent: :destroy,
|
||||||
|
foreign_key: :view_id, foreign_type: :view_type,
|
||||||
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
|
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
|
||||||
has_many :nutrient_quantities, -> { order "lft" }, through: :nutrient_exposures,
|
has_many :nutrient_quantities, -> { order "lft" }, through: :nutrient_exposures,
|
||||||
source: 'quantity'
|
source: 'quantity'
|
||||||
@ -16,7 +17,8 @@ module BodyTracking::ProjectPatch
|
|||||||
extend: BodyTracking::ItemsWithQuantities, through: :measurement_routines
|
extend: BodyTracking::ItemsWithQuantities, through: :measurement_routines
|
||||||
|
|
||||||
has_many :meals, -> { order "eaten_at DESC" }, dependent: :destroy
|
has_many :meals, -> { order "eaten_at DESC" }, dependent: :destroy
|
||||||
has_many :meal_exposures, as: :view, dependent: :destroy,
|
has_many :meal_exposures, -> { where view_type: "Meal" }, dependent: :destroy,
|
||||||
|
foreign_key: :view_id, foreign_type: :view_type,
|
||||||
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
|
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
|
||||||
has_many :meal_quantities, -> { order "lft" }, through: :meal_exposures,
|
has_many :meal_quantities, -> { order "lft" }, through: :meal_exposures,
|
||||||
source: 'quantity'
|
source: 'quantity'
|
||||||
|
Reference in New Issue
Block a user