diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 60af891..9012170 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -16,6 +16,7 @@ def create @user = User.find(session[:user]["id"]) @photo = Photo.find(params[:photo_id]) @comment = @photo.comments.where(user: @user).create!(comment_params) + # @comment = current_user.comments.create!(comment_params), add hidden field to form redirect_to photo_path(@photo) end @@ -36,6 +37,7 @@ def update @comment = Comment.find(params[:id]) @comment.update(comment_params) redirect_to photo_path(@photo) + # redirect_to @photo end #destroy @@ -44,6 +46,7 @@ def destroy @comment = Comment.find(params[:id]) @comment.destroy redirect_to photo_path(@photo) + # redirect_to @photo end private diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 64b2c6a..7734fd8 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -26,6 +26,7 @@ def create @photo.score = 0 @photo.save redirect_to (photo_path(@photo)) + # redirect_to @photo end #edit @@ -61,9 +62,10 @@ def destroy def add_tag @tag = Tag.find_by(tag_name: params[:tag_name]) - if !@tag - @tag = Tag.create!(tag_name: params[:tag_name]) - end + # if !@tag + # @tag = Tag.create!(tag_name: params[:tag_name]) + # end + @tag ||= Tag.create!(tag_name: params[:tag_name]) @tag.categories.create!(photo_id: params[:photo_id]) redirect_to :back end @@ -78,6 +80,7 @@ def upvote @photo = Photo.find(params[:photo_id]) @photo.score += 1 @photo.save + # @photo.update(score: @photo.score += 1) redirect_to photo_path(@photo) end @@ -86,6 +89,7 @@ def downvote @photo = Photo.find(params[:photo_id]) @photo.score -= 1 @photo.save + # @photo.update(score: @photo.score -= 1) redirect_to photo_path(@photo) end @@ -94,9 +98,10 @@ def photo_params params.require(:photo).permit(:title, :photo_url, :user_id) end - private - def comment_params - params.require(:comment).permit(:content) - end + + def comment_params + params.require(:comment).permit(:content) + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 15bef61..de97ab7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -36,6 +36,10 @@ def sign_in! flash[:notice] = message redirect_to action: :sign_in end + + # def current_user + # current_user = session[:user] + # end def sign_out! message = "You're signed out!" diff --git a/app/views/photos/index.html.erb b/app/views/photos/index.html.erb index 7888b1b..e497066 100644 --- a/app/views/photos/index.html.erb +++ b/app/views/photos/index.html.erb @@ -10,7 +10,7 @@