Last active
December 21, 2015 07:39
-
-
Save mecampbellsoup/6273076 to your computer and use it in GitHub Desktop.
Fixing comments controller... I think since line 7 comes after the 'create' in line 6, the user_id isn't being set. EDIT: Found a fix, see below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController < ApplicationController | |
def create | |
if user_signed_in? | |
@event = Event.find(params[:event_id]) | |
@comment = @event.comments.build comment_params | |
binding.pry | |
if @comment.save | |
redirect_to @comment.event | |
else | |
render :action => 'events/show' | |
end | |
else | |
redirect_to new_user_session_path, alert: "Only logged in users can create comments" | |
end | |
end | |
def update | |
redirect_to @comment.event | |
end | |
private | |
def comment_params | |
params.require(:comment).permit(:post, :user_id, :event_id).merge(event_id: params[:event_id]).merge(user_id: current_user.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment