-
Notifications
You must be signed in to change notification settings - Fork 2
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
Blog app - Add forms #8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Baayeh ,
Good job so far!
To Highlight! 👏 🟢
✔️ Good commit messages
✔️ Descriptive Readme file
There are some issues that you still need to work on to go to the next project but you are almost there!
Required Changes ♻️
Check the comments under the review.
Optional suggestions
Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.
You can also consider:
- N/A
Cheers and Happy coding!👏👏👏
Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.
Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.
As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.
app/controllers/posts_controller.rb
Outdated
def create | ||
@post = Post.new(post_params) | ||
@post.author = current_user | ||
if @post.save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Great job with the project. I think you have to make use of the rails method
respond_to
so that you define how requests for html are responded to. You should something similar to the code snippet below:
respond_to do |format|
if @post.save
format.html { redirect_to @post }
else
format.html { render :new }
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for the suggestion. I will implement it.
@comment = Comment.new(comment_params) | ||
@comment.author = current_user | ||
@comment.post = @post | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Your comment controller is missing the new action. Kindly add it.
def new
...
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task requires that we create a form to handle the creation of comments. It did not specifically ask that we create a view for it. So I put the form in the show view of the post controller. It will make it easy for the user to comment on a post easily without having to navigate to another page.
end | ||
end | ||
|
||
def comment_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The comment_params method is suppose to be a private method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might have escaped me 😃 . Thanks for the reminder. I will make it private.
@comment = Comment.new(comment_params) | ||
@comment.author = current_user | ||
@comment.post = @post | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Take a look at the create method below and see how to improve your method
def create
@comment = @current_user.comments.new(params)
@comment.post_id = params[:post_id]
if @comment.save
redirect_to post_path(@comment.post)
else
@article = Post.find(params[:post_id])
redirect_to post_path(@post)
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I will refactor that part.
resources :posts, only: [:index, :show] | ||
resources :users, only: [:index, :show] do | ||
resources :posts, only: [:index, :new, :create, :show] do | ||
resources :comments, only: [:create] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You should have a route for new comments. Youre probabbly missing it because you did not have the new action in your comments controller. Kindly check and add. When I run
rails routes
, I cannot find it among the routes just to be very sure. - The route should be a
GET
-GET /posts/:post_id/comments/new(.:format) comments#new
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task requires that we create a form to handle the creation of comments. It did not specifically ask that we create a view for it. So I put the form in the show view of the post controller. It will make it easy for the user to comment on a post easily without having to navigate to another page.
<div class="form-submit"> | ||
<%= form.submit "Add Comment" %> | ||
</div> | ||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There should be a form in the
views/comments/new.html.erb
file which accepts input for creating comments. This is missing in your folder structure. I am sure this is because you did not have thenew
action in your comments controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task requires that we create a form to handle the creation of comments. It did not specifically ask that we create a view for it. So I put the form in the show view of the post controller. It will make it easy for the user to comment on a post easily without having to navigate to another page.
app/controllers/likes_controller.rb
Outdated
if @like.save | ||
redirect_to user_post_path(@user, @post), notice: 'You have liked this post' | ||
else | ||
flash[:error] = @like.errors.full_messages | ||
redirect_to user_post_path(@user, @post) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think you should make use of the rails
respond_to
method for the same reason I indicated in my comment in your posts controller.
respond_to do |format|
if @like.save
format.html { redirect_to @post }
else
format.html { redirect_to @post }
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STATUS: APPROVED ✔️ ✔️
Hi @Baayeh,
✔️ Posts, comments and likes can be well created
Your project is complete! There is nothing else to say other than... it's time to merge it
Congratulations! 🎉
Cheers and Happy coding!👏👏👏
Feel free to leave any questions or comments in the PR thread if something is not 100% clear. And please, remember to tag me in your question so I can receive the notification.
As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.
Adding forms to accept user inputs
current_user
in theApplicationController
to make current user data available to all controllers.current_user
.current_user
.