Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
garrengotthardt committed Jun 21, 2017
2 parents fc9793d + 00b2979 commit 76f6455
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
31 changes: 21 additions & 10 deletions app/controllers/saver_recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
class SaverRecipesController < ApplicationController

# def new
# @recipe_ingredient = RecipeIngredient.new(params)
# @recipe_ingredient.save
# end
#
def new
@saver_recipe = SaverRecipe.new
end


def create
@recipe = Recipe.find_by(id: params[:saver_recipe][:saved_recipe_id])
@saver_recipe = SaverRecipe.create(saver_id: params[:saver_recipe][:saver_id], saved_recipe_id: params[:saver_recipe][:saved_recipe_id])
redirect_to recipe_path(@recipe)
flash[:notice] = "Successfully saved #{@recipe.author.name}'s recipe #{@recipe.name} to your favorite recipes list"
end


# def create
# @saver_recipe = SaverRecipe.new(saver_recipe_params)
# end
def destroy
@saver_recipe = SaverRecipe.find(params[:id])
@recipe = Recipe.find_by_id(@saver_recipe.saved_recipe_id)
@saver_recipe.destroy
redirect_to recipe_path(@recipe)
flash[:notice] = "Successfully removed #{@recipe.author.name}'s recipe #{@recipe.name} from your favorite recipes list"
end



private
def sacver_recipe_params
params.require(:recipe).permit(:saver_id, :saved_recipe_id)
def saver_recipe_params
params.require(:saver_recipe).permit(:saver_id, :saved_recipe_id)
end

end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class UsersController < ApplicationController
before_action :authenticated, except: [:new, :create]
before_action :authenticated, except: [:new, :create, :index, :show]

def index
@users = User.all
Expand Down
14 changes: 13 additions & 1 deletion app/views/recipes/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
<a class="btn" href="<%= edit_recipe_path(@recipe)%>">Delete Recipe</a>
<% else %>
<!-- THIS BUTTON IS NOT YET WORKING WORKING ON IT NOW -->
<%= link_to "Save Recipe", new_saver_recipe_path(saver_id: current_user.id, saved_recipe_id: @recipe.id) %>
<% if logged_in? %>
<% if current_user.saved_recipes.include?(@recipe) %>
<%= link_to "Unsave", saver_recipe_path(SaverRecipe.find_by(saver_id: current_user.id, saved_recipe_id: @recipe.id)), method: :delete %>
<% else %>
<%= form_for SaverRecipe.new do |f| %>
<%= f.hidden_field :saver_id, :value => current_user.id %>
<%= f.hidden_field :saved_recipe_id, :value => @recipe.id %>
<%= f.submit "Save Recipe"%>
<% end %>
<% end %>
<% else %>
<a class="btn" onclick="Materialize.toast('Please sign up or sign in to save this recipe.', 4000)">Save Recipe</a>
<% end %>
<% end %>
</div><br><br>

Expand Down

0 comments on commit 76f6455

Please sign in to comment.