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
def show | |
@comments = Comment.where(post_id: @post) | |
@random_post = Post.where.not(id: @post).order("RANDOM()").first | |
end |
While working on a bug for a few hours I ran into a solution that wasn't covered by Mackenzie Child. When you push this app to heroku, you will not have a database. There is code in post/show.html.haml that is looking to display a post that will break because there aren't any posts.
The code looks for a post that does not have the same user_id as the post that is displaying, puts it into a collection and gets a random one to display. So I just thought, well it should only show a post if there is more than 1 post.
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
- if Post.count > 1 | |
#random_post | |
%h3 Random Inspiration | |
.post | |
.post_image | |
= link_to (image_tag @random_post.image.url(:small)), post_path(@random_post) | |
.post_content | |
.title | |
%h2= link_to @random_post.title, post_path(@random_post) | |
.data.clearfix | |
%p.username | |
Shared by | |
= @random_post.user.name | |
%p.buttons | |
%span | |
%i.fa.fa-comments-o | |
= @random_post.comments.count | |
%span | |
%i.fa.fa-thumbs-o-up | |
= @random_post.get_likes.size | |
- else | |
#random_post | |
%h3 You have the first post. |
So in line 1 I added an if statement. if Post.count > 1 display the random post else display the sentence You have the first post.
It is not a big deal, since I can populate the database and it takes just one to keep the app from breaking, but in my book its a bug that had to be fixed.
1. Better picture formatting so each pic on index page is the same size |
2. Search function. |
3. Rich text formatting |
4. Social media shareability |
5. Make pictures 30%-50% bigger. Move random box view down to lower right corner. |
6. Add a large version of the picture to have as a background image for each post. |
7. Tie dislike button to comments, so a user has to leave a comment if disliking a post. |
Tune in next week, for the final app.
Kenyacode
Technologies used: carrierwave, acts_as_votable, fog-aws, mini_magick, devise, haml, simple_form, bootstrap-sass, heroku
Github page: https://github.com/kenyacode/dribble
No comments:
Post a Comment