Skip to content

Commit

Permalink
basic valdidations on recipe ingredients form
Browse files Browse the repository at this point in the history
  • Loading branch information
garrengotthardt committed Jun 22, 2017
1 parent 25a55aa commit 7973713
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
5 changes: 3 additions & 2 deletions app/controllers/recipe_ingredients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 5 additions & 6 deletions app/views/recipe_ingredients/_recipe_ingredient_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<%= form_for(@recipe_ingredient) do |t| %>
<%= t.hidden_field :recipe_id, :value => params[:recipe_id] %><br>
<%= t.collection_select :ingredient_id, Ingredient.all, :id, :name, { prompt: "Choose an ingredient" }%><br>
<%= 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" }%><br><br>

<%= t.submit "Add Ingredient to Recipe " %>
<%= t.hidden_field :recipe_id, value: @recipe.id %><br>
<%= t.collection_select :ingredient_id, Ingredient.order(:name), :id, :name, { prompt: "Choose an ingredient*" }, required: true, class:'validate' %><br>
<%= 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" }%><br><br>
<%= t.submit "Add Ingredient to Recipe", class:'btn' %>
<% end %>
3 changes: 0 additions & 3 deletions app/views/recipe_ingredients/new.html.erb

This file was deleted.

8 changes: 1 addition & 7 deletions app/views/recipes/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@
<div id="add_recipe_ingredient_modal" class="modal modal-fixed-footer">
<div class="modal-content">
<h4>Add Ingredient to <%=@recipe.name%></h4>
<%= form_for(@recipe_ingredient) do |t| %>
<%= t.hidden_field :recipe_id, value: @recipe.id %><br>
<%= t.collection_select :ingredient_id, Ingredient.order(:name), :id, :name, { prompt: "Choose an ingredient" }%><br>
<%= 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" }%><br><br>
<%= t.submit "Add Ingredient to Recipe", class:'btn' %>
<% end %>
<%= render 'recipe_ingredients/recipe_ingredient_form' %>
</div>
</div>
<% end %>
Expand Down

0 comments on commit 7973713

Please sign in to comment.