Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Class Pizza
- class Pizza < ApplicationRecord
- has_many :ingredient_uses
- end
- #Class Ingredient
- class Ingredient < ApplicationRecord
- has_many :ingredient_uses
- end
- #Class IngredientUse
- class IngredientUse < ApplicationRecord
- belongs_to :pizza
- belongs_to :ingredient
- end
- #View Show Pizza
- <div class="panel-info">
- <div class="panel-heading">
- <h2><%= @title %></h2>
- </div>
- <div class="panel-body">
- <table class="table">
- <thead>
- <tr>
- <th>Value</th><th>Size</th><th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><%= number_to_currency(@pizza.value, unit: '$') %></td>
- <td><%= @pizza.size %></td>
- <td><%= @pizza.description %></td>
- </tr>
- </tbody>
- </table>
- </div>
- <div class="panel-footer">
- <%= link_to 'Back', pizzas_path, class: "btn btn-default" %>
- <%= link_to 'Edit', edit_pizza_path(@pizza), class: "btn btn-info" %>
- <%= link_to 'Delete', pizza_path(@pizza), method: :delete, data: {confirm: 'Delete this pizza?'}, class: "btn btn-danger" %>
- <%= link_to 'Add Ingredient', new_pizza_ingredient_use_path(@pizza), class: "btn btn-info" %>
- </div>
- </div>
- #Form IngredientUse
- <h2>Add Ingredient</h2>
- <%= form_for @ingredient_use do |f| %>
- <p>
- <%= f.label :quantity %>
- <%= f.text_field :quantity %>
- </p>
- <% end %>
- #IngreditUse Controller
- class IngredientUsesController < ApplicationController
- def new
- @ingredient_use = IngredientUse.new
- end
- def create
- @pizza = Pizza.find(params[:id])
- #rest of code
- end
- private
- def ingredientuses_params
- params.require(:ingredient_use).permit(:quantity, :description, :pizza, :ingredient)
- end
- end
- #Error on click Add ingredient link
- undefined method `ingredient_uses_path' for #<#<Class:0x000000028630b0>:0x00000004b53318>
- Did you mean? ingredient_path
- ingredients_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement