Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #Class Pizza
  2. class Pizza < ApplicationRecord
  3. has_many :ingredient_uses
  4. end
  5.  
  6. #Class Ingredient
  7. class Ingredient < ApplicationRecord
  8. has_many :ingredient_uses
  9. end
  10.  
  11. #Class IngredientUse
  12. class IngredientUse < ApplicationRecord
  13. belongs_to :pizza
  14. belongs_to :ingredient
  15. end
  16.  
  17. #View Show Pizza
  18. <div class="panel-info">
  19. <div class="panel-heading">
  20. <h2><%= @title %></h2>
  21. </div>
  22. <div class="panel-body">
  23. <table class="table">
  24. <thead>
  25. <tr>
  26. <th>Value</th><th>Size</th><th>Description</th>
  27. </tr>
  28. </thead>
  29. <tbody>
  30. <tr>
  31. <td><%= number_to_currency(@pizza.value, unit: '$') %></td>
  32. <td><%= @pizza.size %></td>
  33. <td><%= @pizza.description %></td>
  34. </tr>
  35. </tbody>
  36. </table>
  37. </div>
  38. <div class="panel-footer">
  39. <%= link_to 'Back', pizzas_path, class: "btn btn-default" %>
  40. <%= link_to 'Edit', edit_pizza_path(@pizza), class: "btn btn-info" %>
  41. <%= link_to 'Delete', pizza_path(@pizza), method: :delete, data: {confirm: 'Delete this pizza?'}, class: "btn btn-danger" %>
  42. <%= link_to 'Add Ingredient', new_pizza_ingredient_use_path(@pizza), class: "btn btn-info" %>
  43. </div>
  44. </div>
  45.  
  46. #Form IngredientUse
  47. <h2>Add Ingredient</h2>
  48.  
  49. <%= form_for @ingredient_use do |f| %>
  50.  
  51. <p>
  52. <%= f.label :quantity %>
  53. <%= f.text_field :quantity %>
  54. </p>
  55.  
  56.  
  57. <% end %>
  58.  
  59. #IngreditUse Controller
  60. class IngredientUsesController < ApplicationController
  61.  
  62. def new
  63. @ingredient_use = IngredientUse.new
  64. end
  65.  
  66. def create
  67. @pizza = Pizza.find(params[:id])
  68. #rest of code
  69. end
  70.  
  71. private
  72. def ingredientuses_params
  73. params.require(:ingredient_use).permit(:quantity, :description, :pizza, :ingredient)
  74. end
  75. end
  76.  
  77. #Error on click Add ingredient link
  78. undefined method `ingredient_uses_path' for #<#<Class:0x000000028630b0>:0x00000004b53318>
  79. Did you mean? ingredient_path
  80. ingredients_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement