Ask A Question


You’re not receiving notifications from this thread.

Adding Scheduled Blog Posts Discussion

Hello Chris, I am facing the issue while sign in locally (it shows password and email are invalid) even my production site is not giving me this issue, Please help.
Thanks in advance!


I have resolved this issue by my own, but I do not know why do I had to run rails db:seed command again to populate my database with the predefined seed data that I had already set up in my seed.rb file.


In the last video we changed the database to PostgreSQL and had to re-create the databases. As a result, this caused us to lose our data on our local machines. Therefore we needed to run rails db:seed again to populate it with the user so that we can login.

Hopefully that explains the issues you were having :D


Sure, Thanks a lot!


Hi Chris, one thing wasn´t clear to me. Why do we need those helper methods (draft?, published?, scheduled?), since setting the scopes already give us the ability to get BlogPost.draf and so on?


The scopes work at the class level, so those will get you a collection of BlogPost records that are all either drafts, published, or scheduled.

The helpers are instance methods, designed to be used with a single blog post instance/record.

The helpers/instance methods are nice because it will not always be the case that you want a collection of draft posts, for example, you may be on the show page for a particular blog post and you could then use the helpers/instance methods to check the published_at status of that particular blog post instance.
Hope that helps!


Thanks! Great explanation :))


The CSS for draft posts is working, but for some reason the CSS isn't being applied to scheduled posts.



Doesn't work:


My posts aren't displaying in the correct order. I have the following line in my blog_post.rb:

scope :sorted, -> { order(published_at: :desc, updated_at: :desc) }

And in my controller I have:

def index
@blog_posts = user_signed_in? ? BlogPost.sorted : BlogPost.published.sorted

The order seems to be the opposite of what shows in the video.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.