sausage-sandwich/ruby_sandwich

View on GitHub
apps/web/templates/profile/recipes/recipe_ingredients/batch_edit.html.slim

Summary

Maintainability
Test Coverage
= link_to "<- #{recipe.title}", routes.recipe_path(id: recipe.id)

.row
  .col-md-12
    = form_for :recipe, routes.profile_recipe_ingredients_path(recipe_id: recipe.id), values: { recipe: recipe } do
      - table class: 'table w-100'
        - tr
          - th
            - I18n.t('title', scope: 'views.recipes.recipe_ingredients.batch_edit')
          - th
            - I18n.t('protein_per_100_g', scope: 'views.recipes.recipe_ingredients.batch_edit')
          - th
            - I18n.t('fat_per_100_g', scope: 'views.recipes.recipe_ingredients.batch_edit')
          - th
            - I18n.t('carbs_per_100_g', scope: 'views.recipes.recipe_ingredients.batch_edit')
        - fields_for_collection :recipe_ingredients do |i, recipe_ingredient|
          - tr
            - td
              - number_field :id, hidden: true
              = label ingredient_title(recipe_ingredient)
              - if Unit::TRIVIAL_UNITS.include?(recipe_ingredient.unit)
                = label "(#{I18n.t('in_1_unit_of_ingredient', unit: I18n.t(recipe_ingredient.unit, scope: 'units', count: 1), scope: 'views.recipes.recipe_ingredients.batch_edit')}"
                - number_field :unit_g, value: display_g(recipe_ingredient.unit_mg), step: 'any', class: 'text-right small-number-field'
                - span "#{I18n.t('g', scope: 'units', count: 1)})"
            - td
              - number_field :protein_g, value: display_g(recipe_ingredient.protein_mg), step: 'any', class: 'text-right small-number-field'
              - span I18n.t('g', scope: 'units', count: 1)
            - td
              - number_field :fat_g, value: display_g(recipe_ingredient.fat_mg), step: 'any', class: 'text-right small-number-field'
              - span I18n.t('g', scope: 'units', count: 1)
            - td
              - number_field :carbohydrates_g, value: display_g(recipe_ingredient.carbohydrates_mg), step: 'any', class: 'text-right small-number-field'
              - span I18n.t('g', scope: 'units', count: 1)
      - submit I18n.t('save'), class: 'btn btn-primary'