Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added comments as feedback #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -44,6 +46,7 @@ def destroy
@comment = Comment.find(params[:id])
@comment.destroy
redirect_to photo_path(@photo)
# redirect_to @photo
end

private
Expand Down
19 changes: 12 additions & 7 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create
@photo.score = 0
@photo.save
redirect_to (photo_path(@photo))
# redirect_to @photo
end

#edit
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
2 changes: 1 addition & 1 deletion app/views/photos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<div class="index_photo_title">
<%= link_to photo.title, photo_path(photo)%>
<%= link_to photo.title, photo_path(photo)%> <!-- path can be just photo -->
</div>

<div class="index_photo_score">
Expand Down