diff --git a/Gemfile b/Gemfile
index 8e5ff99..f474f85 100644
--- a/Gemfile
+++ b/Gemfile
@@ -22,6 +22,7 @@ gem 'simple_form'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'devise'
gem 'paperclip'
+gem 'omniauth-github'
# Use jquery as the JavaScript library
gem 'jquery-rails'
diff --git a/Gemfile.lock b/Gemfile.lock
index c0b4272..429d739 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -51,7 +51,6 @@ GEM
climate_control (0.2.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
- cocoon (1.2.10)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
@@ -68,9 +67,12 @@ GEM
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.7.0)
+ faraday (0.12.2)
+ multipart-post (>= 1.2, < 3)
ffi (1.9.18)
globalid (0.4.0)
activesupport (>= 4.2.0)
+ hashie (3.5.6)
i18n (0.8.6)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
@@ -79,6 +81,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
+ jwt (1.5.6)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -94,9 +97,26 @@ GEM
mini_portile2 (2.2.0)
minitest (5.10.3)
multi_json (1.12.1)
+ multi_xml (0.6.0)
+ multipart-post (2.0.0)
nio4r (2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
+ oauth2 (1.4.0)
+ faraday (>= 0.8, < 0.13)
+ jwt (~> 1.0)
+ multi_json (~> 1.3)
+ multi_xml (~> 0.5)
+ rack (>= 1.2, < 3)
+ omniauth (1.6.1)
+ hashie (>= 3.4.6, < 3.6.0)
+ rack (>= 1.6.2, < 3)
+ omniauth-github (1.3.0)
+ omniauth (~> 1.5)
+ omniauth-oauth2 (>= 1.4.0, < 2.0)
+ omniauth-oauth2 (1.4.0)
+ oauth2 (~> 1.0)
+ omniauth (~> 1.2)
orm_adapter (0.5.0)
paperclip (5.0.0)
activemodel (>= 4.2.0)
@@ -192,12 +212,12 @@ PLATFORMS
DEPENDENCIES
bootstrap-sass (~> 3.3.6)
byebug
- cocoon
coffee-rails (~> 4.2)
devise
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
+ omniauth-github
paperclip
puma (~> 3.0)
rails (~> 5.0.4)
diff --git a/README.md b/README.md
index b08e36a..5e03c39 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-# README
-
#Recipe App
This app will allow you to create or browse recipes with the features of adding ingredients, images and directions.
diff --git a/app/assets/javascripts/comments.coffee b/app/assets/javascripts/comments.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/comments.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/omniauth_callbacks_controller.coffee b/app/assets/javascripts/omniauth_callbacks_controller.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/omniauth_callbacks_controller.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 3f4b8d7..67cb0ec 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -16,7 +16,7 @@
@mixin box-shadow {
- -webkit-box-shadow: rgba(0, 0, 0, 0.09) 0 2px 0;
+ -webkit-box-shadow: rgba(0, 0, 0, 0.09) 0 5px 0;
-moz-box-shadow: rgba(0, 0, 0, 0.09) 0 2px 0;
box-shadow: rgba(0, 0, 0, 0.09) 0 2px 0;
}
diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss
new file mode 100644
index 0000000..e730912
--- /dev/null
+++ b/app/assets/stylesheets/comments.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Comments controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 1c07694..13be47b 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,3 +1,8 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
+
+ def after_sign_in_path_for(resource)
+ request.env['omniauth.origin'] || root_path
+ end
+
end
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
new file mode 100644
index 0000000..b4365cc
--- /dev/null
+++ b/app/controllers/comments_controller.rb
@@ -0,0 +1,16 @@
+class CommentsController < ApplicationController
+ def create
+ @recipe = Recipe.find(params[:recipe_id])
+ @comment = @recipe.comments.create(comment_params)
+ redirect_to recipe_path(@recipe)
+ end
+
+
+ private
+
+ def comment_params
+ params.require(:comment).permit(:rating, :body, :recipe_id)
+ end
+
+
+end
diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb
new file mode 100644
index 0000000..0e63509
--- /dev/null
+++ b/app/controllers/omniauth_callbacks_controller.rb
@@ -0,0 +1,8 @@
+class OmniauthCallbacksController < Devise::OmniauthCallbacksController
+
+ def github
+ @user = User.from_omniauth(request.env["omniauth.auth"])
+ sign_in_and_redirect @user
+ end
+
+end
diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb
index 5b374bb..9836266 100644
--- a/app/controllers/recipes_controller.rb
+++ b/app/controllers/recipes_controller.rb
@@ -1,3 +1,4 @@
+require 'byebug'
class RecipesController < ApplicationController
before_action :find_recipe, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
@@ -8,15 +9,14 @@ def index
def new
@recipe = Recipe.new
- @ingredients = @recipe.ingredients.build
- @ingredient_recipes = 3.times.collect { @recipe.recipe_ingredients.build }
+ @ingredients = 4.times.collect { @recipe.ingredients.build }
+ # @comments = @recipe.comments.build
end
def create
@recipe = Recipe.new(recipe_params)
- @recipe = current_user.recipes.new(recipe_params)
+ @recipe = current_user.recipes.build(recipe_params)
if @recipe.save
- @recipe.add_ingredients(recipe_ingredient_params)
redirect_to recipe_path(@recipe), notice: "Your recipe has successfully been added"
else
render 'new'
@@ -24,13 +24,10 @@ def create
end
def edit
- # 3.times.collect {@recipe.ingredients.build}
- @ingredient_recipes = 3.times.collect { @recipe.recipe_ingredients.build }
end
def update
if @recipe.update(recipe_params)
- @recipe.add_ingredients(recipe_ingredient_params)
redirect_to @recipe, notice: "Your recipe has successfully been updated"
else
render 'edit'
@@ -38,6 +35,7 @@ def update
end
def show
+ @comments = @recipe.comments
end
def destroy
@@ -52,12 +50,7 @@ def find_recipe
end
def recipe_params
- params.require(:recipe).permit(:name, :description, :image, :directions)
+ params.require(:recipe).permit(:name, :description, :image, :directions, :ingredient_ids => [], :ingredients_attributes => [:name])
end
- def recipe_ingredient_params
- params.require(:recipe).permit(recipe_ingredients_attributes: [:ingredient_id, ingredient: [:name]])
- end
-
-
end
diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb
new file mode 100644
index 0000000..0ec9ca5
--- /dev/null
+++ b/app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
diff --git a/app/helpers/omniauth_callbacks_controller_helper.rb b/app/helpers/omniauth_callbacks_controller_helper.rb
new file mode 100644
index 0000000..0f1a0bd
--- /dev/null
+++ b/app/helpers/omniauth_callbacks_controller_helper.rb
@@ -0,0 +1,2 @@
+module OmniauthCallbacksControllerHelper
+end
diff --git a/app/models/comment.rb b/app/models/comment.rb
new file mode 100644
index 0000000..4337fc0
--- /dev/null
+++ b/app/models/comment.rb
@@ -0,0 +1,9 @@
+class Comment < ApplicationRecord
+ belongs_to :recipe
+ belongs_to :user
+
+
+ validates_inclusion_of :rating, :in => 1..5, message: "is between 1-5"
+
+
+end
diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb
index 06a1884..0930476 100644
--- a/app/models/ingredient.rb
+++ b/app/models/ingredient.rb
@@ -2,4 +2,7 @@ class Ingredient < ApplicationRecord
has_many :recipe_ingredients
has_many :recipes, through: :recipe_ingredients
+ validates :name, uniqueness: { case_sensitive: false },
+ allow_blank: true
+
end
diff --git a/app/models/recipe.rb b/app/models/recipe.rb
index b01d248..882c1a6 100644
--- a/app/models/recipe.rb
+++ b/app/models/recipe.rb
@@ -1,9 +1,13 @@
+# require 'byebug'
class Recipe < ApplicationRecord
belongs_to :user, optional: true
has_many :recipe_ingredients
has_many :ingredients, through: :recipe_ingredients
+ has_many :comments
+
+ # accepts_nested_attributes_for :recipe_ingredients
+
- accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true
accepts_nested_attributes_for :ingredients, allow_destroy: true
@@ -11,30 +15,12 @@ class Recipe < ApplicationRecord
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
-
-
- def add_ingredients(params)
- params[:recipe_ingredients_attributes].each do |k, recipe_ingredient|
-
- if recipe_ingredient[:recipe_id].present?
- @ingredient = Ingredient.find_or_create_by(params[:id])
-
- elsif recipe_ingredient[:ingredient_id].present?
- @ingredient = Ingredient.find_by(id: recipe_ingredient[:ingredient_id])
- end
-
- if recipe_ingredient[:recipe_id].present?
- RecipeIngredient.create( ingredient_id: ingredient.id, recipe_id: self.id )
- end
+ def ingredients_attributes=(ingredients_attributes)
+ ingredients_attributes.each do |k, attribute|
+ ingredient = Ingredient.find_or_create_by(attribute)
+ ingredients << ingredient if ingredient.persisted?
end
end
- # def add_ingredients(params)
- # params[:ingredients_attributes].each do |k, recipe_ingredient|
- # if ingredient[:id].present?
- # @recipe_ingredient = RecipeIngredient.find_or_create_by(params[:id])
- # elsif ingredient[:name].present?
- # end
-
end
diff --git a/app/models/recipe_ingredient.rb b/app/models/recipe_ingredient.rb
index e498bc4..30a7118 100644
--- a/app/models/recipe_ingredient.rb
+++ b/app/models/recipe_ingredient.rb
@@ -2,5 +2,4 @@ class RecipeIngredient < ApplicationRecord
belongs_to :recipe
belongs_to :ingredient
-
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 033ab23..7b2648e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,7 +2,17 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable
+ :recoverable, :rememberable, :trackable, :validatable,
+ :omniauthable
has_many :recipes
-
+
+ def self.from_omniauth(auth)
+ where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
+ user.provider = auth.provider
+ user.uid = auth.uid
+ user.email = auth.info.email
+ user.password = Devise.friendly_token[0,20]
+ end
+ end
+
end
diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb
new file mode 100644
index 0000000..657bf07
--- /dev/null
+++ b/app/views/comments/_comment.html.erb
@@ -0,0 +1,12 @@
+<%= div_for @comments do |comment| %>
+
+
+ Posted
+ <%= time_ago_in_words(comment.created_at) %>
+ ago
+
+
+ <%= comment.body %>
+ <%= comment.rating %>
+
+<% end %>
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb
new file mode 100644
index 0000000..759c0a5
--- /dev/null
+++ b/app/views/comments/_form.html.erb
@@ -0,0 +1,11 @@
+<%= simple_form_for([@recipe, @recipe.comments.build]) do |f| %>
+<%= f.label :rating %>
+ <%= f.number_field :rating %>
+
+
+<%= f.label :comment %>
+ <%= f.text_area :body %>
+
+<%= f.submit %>
+
+<% end %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index ceffdec..d92467c 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -7,6 +7,7 @@
<%= csrf_meta_tags %>
+