diff --git a/app/controllers/recipe_ingredients_controller.rb b/app/controllers/recipe_ingredients_controller.rb index 44f1265..aaf1714 100644 --- a/app/controllers/recipe_ingredients_controller.rb +++ b/app/controllers/recipe_ingredients_controller.rb @@ -10,11 +10,12 @@ def new def create @recipe_ingredient = RecipeIngredient.new(recipe_ingredient_params) + @recipe = Recipe.find_by_id(params[:recipe_ingredient][:recipe_id]) if @recipe_ingredient.save - # binding.pry redirect_to recipe_path(params[:recipe_ingredient][:recipe_id]) else - render :new + redirect_to recipe_path(@recipe) + flash[:notice] = "Recipe ingredient was not complete so did not save" end end diff --git a/app/views/recipe_ingredients/_recipe_ingredient_form.html.erb b/app/views/recipe_ingredients/_recipe_ingredient_form.html.erb index 9b92055..35e499d 100644 --- a/app/views/recipe_ingredients/_recipe_ingredient_form.html.erb +++ b/app/views/recipe_ingredients/_recipe_ingredient_form.html.erb @@ -1,8 +1,7 @@ <%= form_for(@recipe_ingredient) do |t| %> - <%= t.hidden_field :recipe_id, :value => params[:recipe_id] %>
- <%= t.collection_select :ingredient_id, Ingredient.all, :id, :name, { prompt: "Choose an ingredient" }%>
- <%= t.number_field :quantity, placeholder: 'Quantity', step: :any %> - <%= t.select :units, ['Cup(s)', 'Gram(s)', 'Kilogram(s)', 'Liter(s)', 'Mililiter(s)', 'Pound(s)', 'Ounce(s)', 'Pint(s)', 'Teaspoon(s)', 'Tablespoon(s)'], { prompt: "Choose a unit of measure" }%>

- - <%= t.submit "Add Ingredient to Recipe " %> + <%= t.hidden_field :recipe_id, value: @recipe.id %>
+ <%= t.collection_select :ingredient_id, Ingredient.order(:name), :id, :name, { prompt: "Choose an ingredient*" }, required: true, class:'validate' %>
+ <%= t.number_field :quantity, placeholder: 'quantity', step: :any, min: '.01', required: true, class: 'validate'%> + <%= t.select :units, ['cup(s)', 'gram(s)', 'kilogram(s)', 'liter(s)', 'mililiter(s)', 'pound(s)', 'ounce(s)', 'pint(s)', 'teaspoon(s)', 'tablespoon(s)'], { prompt: "Choose a unit of measure" }%>

+ <%= t.submit "Add Ingredient to Recipe", class:'btn' %> <% end %> diff --git a/app/views/recipe_ingredients/new.html.erb b/app/views/recipe_ingredients/new.html.erb deleted file mode 100644 index a29a2c4..0000000 --- a/app/views/recipe_ingredients/new.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

New Recipe Ingredient

- -<%= render "recipe_ingredient_form" %> diff --git a/app/views/recipes/show.erb b/app/views/recipes/show.erb index ff967f3..ca87a59 100644 --- a/app/views/recipes/show.erb +++ b/app/views/recipes/show.erb @@ -85,13 +85,7 @@ <% end %>